/*
 * Copyright 2000-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package jetbrains.buildServer.tools;

import java.net.URI;
import java.net.URL;

import jetbrains.buildServer.tools.JDKTools;
import jetbrains.buildServer.tools.JDKTools.JDKUrlResolver;
import jetbrains.buildServer.tools.JDKTools.LastJDKVersionProvider;
import junit.framework.Assert;

import org.junit.Test;

public class JDKURLResolverTest extends AbstractToolingTestCase {

  @Test
  public void getLatestJDK() throws Exception {
    long startTime = System.currentTimeMillis();
    try {
      final URL latest = JDKUrlResolver.getLatestJDK();
      System.out.println(String.format("Found latest JDK url '%s'", latest));
      Assert.assertNotNull(latest);
    } finally {
      System.out.println(String.format("JDK Last version checking took %dms", System.currentTimeMillis() - startTime));
    }
  }

  @Test
  public void LastJDKVersionProvider_version_parser() throws Exception {
    final String version = new JDKTools.LastJDKVersionProvider().buildVersion("6u24");
    Assert.assertEquals("1.6.0_24", version);
  }

  @Test
  public void LastJDKVersionProvider() throws Exception {
    long startTime = System.currentTimeMillis();
    try {
      final LastJDKVersionProvider provider = new JDKTools.LastJDKVersionProvider();
      final String version = provider.getVersion();
      Assert.assertNotNull(version);
      final URI location = provider.getLocation();
      Assert.assertNotNull(location);
    } finally {
      System.out.println(String.format("JDK Last version providing took %dms", System.currentTimeMillis() - startTime));
    }
  }

}
