<commit_before>/*
 * Copyright 2012 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.forge.addon.maven.dependencies;

import java.util.List;
import java.util.Set;

import org.jboss.forge.addon.dependencies.Coordinate;
import org.jboss.forge.addon.dependencies.Dependency;
import org.jboss.forge.addon.dependencies.DependencyMetadata;
import org.jboss.forge.addon.dependencies.DependencyNode;
import org.jboss.forge.addon.dependencies.DependencyQuery;
import org.jboss.forge.addon.dependencies.builder.CoordinateBuilder;
import org.jboss.forge.addon.dependencies.builder.DependencyBuilder;
import org.jboss.forge.addon.dependencies.builder.DependencyQueryBuilder;
import org.jboss.forge.furnace.manager.maven.MavenContainer;
import org.jboss.forge.furnace.util.Predicate;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class MavenDependencyResolverTest
{
   private MavenDependencyResolver resolver;
   private Predicate<Dependency> addonFilter = new Predicate<Dependency>()
   {
      @Override
      public boolean accept(Dependency dependency)
      {
         return "forge-addon".equals(dependency.getCoordinate().getClassifier());
      }
   };

   @Before
   public void setUp()
   {
      resolver = new MavenDependencyResolver(new FileResourceFactory(), new MavenContainer());
   }

   @Test
   public void testResolveClassifiedArtifact() throws Exception
   {
      CoordinateBuilder coordinate = CoordinateBuilder.create("org.jboss.forge:resources:2.0.0.Alpha3")
               .setClassifier("forge-addon");
      DependencyQueryBuilder query = DependencyQueryBuilder.create(coordinate).setFilter(addonFilter);
      Set<Dependency> artifacts = resolver.resolveDependencies(query);
      Assert.assertFalse(artifacts.isEmpty());
      Assert.assertEquals(3, artifacts.size());
      Dependency dependency = artifacts.iterator().next();
      Assert.assertEquals("forge-addon", dependency.getCoordinate().getClassifier());
      Assert.assertNotNull(dependency.getScopeType());
   }

   @Test(expected = RuntimeException.class)
   public void testResolveWildcardArtifactId() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder.create(CoordinateBuilder.create().setGroupId("org.jboss.forge")
               .setArtifactId("").setClassifier("forge-addon"));
      Set<Dependency> coreAddons = resolver.resolveDependencies(query);
      Assert.assertFalse(coreAddons.isEmpty());
   }

   @Test
   public void testResolveVersions() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder.create(CoordinateBuilder
               .create("org.jboss.forge:dependencies-api"));
      List<Coordinate> versions = resolver.resolveVersions(query);
      Assert.assertNotNull(versions);
      Assert.assertFalse(versions.isEmpty());
   }

   @Test
   public void testResolveVersions2() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder.create(CoordinateBuilder
               .create("javax.annotation:jsr250-api"));
      List<Coordinate> versions = resolver.resolveVersions(query);
      Assert.assertNotNull(versions);
      Assert.assertFalse(versions.isEmpty());
   }

   @Test
   public void testResolveVersionsDependency() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder.create(CoordinateBuilder
               .create("org.jboss.forge:maven-api"));
      List<Coordinate> versions = resolver.resolveVersions(query);
      Assert.assertNotNull(versions);
      Assert.assertFalse(versions.isEmpty());
   }

   @Test
   public void testResolveArtifact() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder
               .create("org.jboss.forge:resources:jar:forge-addon:2.0.0.Alpha3");
      Dependency artifact = resolver.resolveArtifact(query);
      Assert.assertNotNull(artifact);
      Assert.assertTrue("Artifact does not exist: " + artifact, artifact.getArtifact().exists());
   }

   @Test
   public void testResolveMetadata() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder
               .create("org.jboss.forge:resources:jar:forge-addon:2.0.0.Alpha3");
      DependencyMetadata metadata = resolver.resolveDependencyMetadata(query);
      Assert.assertNotNull(metadata);
      Assert.assertTrue(metadata.getDependencies().contains(
               DependencyBuilder.create("junit:junit:4.11")));
   }

   @Test
   public void testResolveDependencyHierarchy() throws Exception
   {
      DependencyNode root = resolver
               .resolveDependencyHierarchy(DependencyQueryBuilder
                        .create("org.jboss.forge:resources:jar:forge-addon:2.0.0.Alpha3"));
      Assert.assertNotNull(root);
      Assert.assertEquals(5, root.getChildren().size());
      Assert.assertEquals("convert", root.getChildren().get(1).getDependency().getCoordinate().getArtifactId());
      // TODO: ui-hints was changed to ui-spi since 2.0.0.Alpha5
      Assert.assertEquals("ui-hints", root.getChildren().get(2).getDependency().getCoordinate().getArtifactId());
   }
}
<commit_msg>Changed test resolution due to changes in Nexus repository<commit_after>/*
 * Copyright 2012 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package org.jboss.forge.addon.maven.dependencies;

import java.util.List;
import java.util.Set;

import org.jboss.forge.addon.dependencies.Coordinate;
import org.jboss.forge.addon.dependencies.Dependency;
import org.jboss.forge.addon.dependencies.DependencyMetadata;
import org.jboss.forge.addon.dependencies.DependencyNode;
import org.jboss.forge.addon.dependencies.DependencyQuery;
import org.jboss.forge.addon.dependencies.builder.CoordinateBuilder;
import org.jboss.forge.addon.dependencies.builder.DependencyBuilder;
import org.jboss.forge.addon.dependencies.builder.DependencyQueryBuilder;
import org.jboss.forge.furnace.manager.maven.MavenContainer;
import org.jboss.forge.furnace.util.Predicate;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * @author <a href="mailto:<EMAIL>"><NAME>, III</a>
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class MavenDependencyResolverTest
{
   private MavenDependencyResolver resolver;
   private Predicate<Dependency> addonFilter = new Predicate<Dependency>()
   {
      @Override
      public boolean accept(Dependency dependency)
      {
         return "forge-addon".equals(dependency.getCoordinate().getClassifier());
      }
   };

   @Before
   public void setUp()
   {
      resolver = new MavenDependencyResolver(new FileResourceFactory(), new MavenContainer());
   }

   @Test
   public void testResolveClassifiedArtifact() throws Exception
   {
      CoordinateBuilder coordinate = CoordinateBuilder.create("org.jboss.forge:resources:2.0.0.Alpha3")
               .setClassifier("forge-addon");
      DependencyQueryBuilder query = DependencyQueryBuilder.create(coordinate).setFilter(addonFilter);
      Set<Dependency> artifacts = resolver.resolveDependencies(query);
      Assert.assertFalse(artifacts.isEmpty());
      Assert.assertEquals(3, artifacts.size());
      Dependency dependency = artifacts.iterator().next();
      Assert.assertEquals("forge-addon", dependency.getCoordinate().getClassifier());
      Assert.assertNotNull(dependency.getScopeType());
   }

   @Test(expected = RuntimeException.class)
   public void testResolveWildcardArtifactId() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder.create(CoordinateBuilder.create().setGroupId("org.jboss.forge")
               .setArtifactId("").setClassifier("forge-addon"));
      Set<Dependency> coreAddons = resolver.resolveDependencies(query);
      Assert.assertFalse(coreAddons.isEmpty());
   }

   @Test
   public void testResolveVersions() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder.create(CoordinateBuilder
               .create("org.jboss.forge:dependencies-api"));
      List<Coordinate> versions = resolver.resolveVersions(query);
      Assert.assertNotNull(versions);
      Assert.assertFalse(versions.isEmpty());
   }

   @Test
   public void testResolveVersions2() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder.create(CoordinateBuilder
               .create("org.jboss.forge.addon:maven-api"));
      List<Coordinate> versions = resolver.resolveVersions(query);
      Assert.assertNotNull(versions);
      Assert.assertFalse(versions.isEmpty());
   }

   @Test
   public void testResolveVersionsDependency() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder.create(CoordinateBuilder
               .create("org.jboss.forge:resources-api"));
      List<Coordinate> versions = resolver.resolveVersions(query);
      Assert.assertNotNull(versions);
      Assert.assertFalse(versions.isEmpty());
   }

   @Test
   public void testResolveArtifact() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder
               .create("org.jboss.forge:resources:jar:forge-addon:2.0.0.Alpha3");
      Dependency artifact = resolver.resolveArtifact(query);
      Assert.assertNotNull(artifact);
      Assert.assertTrue("Artifact does not exist: " + artifact, artifact.getArtifact().exists());
   }

   @Test
   public void testResolveMetadata() throws Exception
   {
      DependencyQuery query = DependencyQueryBuilder
               .create("org.jboss.forge:resources:jar:forge-addon:2.0.0.Alpha3");
      DependencyMetadata metadata = resolver.resolveDependencyMetadata(query);
      Assert.assertNotNull(metadata);
      Assert.assertTrue(metadata.getDependencies().contains(
               DependencyBuilder.create("junit:junit:4.11")));
   }

   @Test
   public void testResolveDependencyHierarchy() throws Exception
   {
      DependencyNode root = resolver
               .resolveDependencyHierarchy(DependencyQueryBuilder
                        .create("org.jboss.forge:resources:jar:forge-addon:2.0.0.Alpha3"));
      Assert.assertNotNull(root);
      Assert.assertEquals(5, root.getChildren().size());
      Assert.assertEquals("convert", root.getChildren().get(1).getDependency().getCoordinate().getArtifactId());
      // TODO: ui-hints was changed to ui-spi since 2.0.0.Alpha5
      Assert.assertEquals("ui-hints", root.getChildren().get(2).getDependency().getCoordinate().getArtifactId());
   }
}

{'fraction_non_alphanumeric': 0.11697441184740838, 'fraction_numerical': 0.007029712250445215, 'mean_word_length': 4.007038948850305, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3878286', 'n_tokens_mistral': 3125, 'n_tokens_neox': 2905, 'n_words': 476}