Пример #1
0
  @Test
  public void checkGAVCStaticGeneration() {
    DbArtifact dbArtifact = new DbArtifact();
    dbArtifact.setGroupId("com.axway.test");
    dbArtifact.setArtifactId("UidTest");
    dbArtifact.setVersion("1.0.0-SNAPSHOT");
    dbArtifact.setClassifier("win");
    dbArtifact.setType("jar");
    dbArtifact.setExtension("jar");

    Artifact artifact =
        DataModelFactory.createArtifact(
            dbArtifact.getGroupId(),
            dbArtifact.getArtifactId(),
            dbArtifact.getVersion(),
            dbArtifact.getClassifier(),
            dbArtifact.getType(),
            dbArtifact.getExtension());

    assertEquals(dbArtifact.getGavc(), DbArtifact.generateGAVC(artifact));
    assertEquals(
        dbArtifact.getGavc(),
        DbArtifact.generateGAVC(
            dbArtifact.getGroupId(),
            dbArtifact.getArtifactId(),
            dbArtifact.getVersion(),
            dbArtifact.getClassifier(),
            dbArtifact.getExtension()));
  }
Пример #2
0
  @Test
  public void testGetArtifact() {
    final DbArtifact dbArtifact = new DbArtifact();
    dbArtifact.setGroupId("groupId");
    dbArtifact.setArtifactId("artifactId");
    dbArtifact.setVersion("1.0.0-SNAPSHOT");
    dbArtifact.setClassifier("win");
    dbArtifact.setType("component");
    dbArtifact.setExtension("jar");
    dbArtifact.setDownloadUrl("nowhere");
    dbArtifact.setSize("10Mo");
    dbArtifact.setProvider("provider");

    final DbLicense license = new DbLicense();
    license.setName("licenseId");
    dbArtifact.addLicense(license);

    final ModelMapper modelMapper = new ModelMapper(mock(RepositoryHandler.class));
    final Artifact artifact = modelMapper.getArtifact(dbArtifact);

    assertEquals(dbArtifact.getGroupId(), artifact.getGroupId());
    assertEquals(dbArtifact.getArtifactId(), artifact.getArtifactId());
    assertEquals(dbArtifact.getVersion(), artifact.getVersion());
    assertEquals(dbArtifact.getClassifier(), artifact.getClassifier());
    assertEquals(dbArtifact.getType(), artifact.getType());
    assertEquals(dbArtifact.getExtension(), artifact.getExtension());
    assertEquals(dbArtifact.getSize(), artifact.getSize());
    assertEquals(dbArtifact.getDownloadUrl(), artifact.getDownloadUrl());
    assertEquals(dbArtifact.getProvider(), artifact.getProvider());
    assertEquals(1, artifact.getLicenses().size());
    assertEquals("licenseId", artifact.getLicenses().get(0));
  }
Пример #3
0
 @Test
 public void checkGavc() {
   DbArtifact artifact = new DbArtifact();
   artifact.setGroupId("com.axway.test");
   artifact.setArtifactId("UidTest");
   artifact.setVersion("1.0.0-SNAPSHOT");
   artifact.setClassifier("win");
   artifact.setType("jar");
   artifact.setExtension("jar");
   assertEquals("com.axway.test:UidTest:1.0.0-SNAPSHOT:win:jar", artifact.getGavc());
 }
Пример #4
0
 @Test
 public void checkToString() {
   DbArtifact artifact = new DbArtifact();
   artifact.setGroupId("com.axway.test");
   artifact.setArtifactId("UidTest");
   artifact.setVersion("1.0.0-SNAPSHOT");
   artifact.setClassifier("win");
   artifact.setType("jar");
   assertEquals(
       "GroupId: com.axway.test, ArtifactId: UidTest, Version: 1.0.0-SNAPSHOT",
       artifact.toString());
 }
Пример #5
0
  @Test
  public void getDependencyFromDbDependency() {
    final DbArtifact dbArtifact = new DbArtifact();
    dbArtifact.setGroupId("org.axway.grapes");
    dbArtifact.setArtifactId("artifact1");
    dbArtifact.setVersion("1.0.0-SNAPSHOT");
    dbArtifact.setExtension("jar");

    final DbDependency dbDependency = new DbDependency();
    dbDependency.setScope(Scope.RUNTIME);
    dbDependency.setTarget(dbArtifact.getGavc());

    final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class);
    when(repositoryHandler.getArtifact(dbArtifact.getGavc())).thenReturn(dbArtifact);

    final ModelMapper modelMapper = new ModelMapper(repositoryHandler);
    final Dependency dependency = modelMapper.getDependency(dbDependency, "sourceName", "123456");

    assertEquals(dbDependency.getTarget(), dependency.getTarget().getGavc());
    assertEquals(dbDependency.getScope(), dependency.getScope());
    assertEquals("sourceName", dependency.getSourceName());
    assertEquals("123456", dependency.getSourceVersion());
  }
Пример #6
0
  @Test
  public void getModule() {
    final DbModule dbModule = new DbModule();
    dbModule.setName("root");
    dbModule.setVersion("1.0.0-SNAPSHOT");

    final DbArtifact dbArtifact = new DbArtifact();
    dbArtifact.setGroupId("com.axway.root");
    dbArtifact.setArtifactId("artifact1");
    dbArtifact.setVersion("1.0.0-SNAPSHOT");
    dbArtifact.setClassifier("win");
    dbArtifact.setType("component");
    dbArtifact.setExtension("jar");
    dbModule.addArtifact(dbArtifact);

    final DbArtifact dbThirdParty = new DbArtifact();
    dbThirdParty.setGroupId("org.apache");
    dbThirdParty.setArtifactId("all");
    dbThirdParty.setVersion("6.8.0-5426");
    dbThirdParty.setType("jar");
    dbThirdParty.setExtension("jar");

    dbModule.addDependency(dbThirdParty.getGavc(), Scope.COMPILE);

    final DbModule dbSubmodule = new DbModule();
    dbSubmodule.setSubmodule(true);
    dbSubmodule.setName("sub1");
    dbSubmodule.setVersion("1.0.0-SNAPSHOT");

    final DbArtifact dbArtifact2 = new DbArtifact();
    dbArtifact2.setGroupId("com.axway.root.sub1");
    dbArtifact2.setArtifactId("artifactSub1");
    dbArtifact2.setVersion("1.0.0-SNAPSHOT");
    dbArtifact2.setExtension("jar");
    dbSubmodule.addArtifact(dbArtifact2);

    final DbArtifact dbThirdParty2 = new DbArtifact();
    dbThirdParty2.setGroupId("org.lol");
    dbThirdParty2.setArtifactId("all");
    dbThirdParty2.setVersion("1.2.3-4");
    dbThirdParty2.setExtension("jar");

    dbSubmodule.addDependency(dbThirdParty2.getGavc(), Scope.PROVIDED);
    dbModule.addSubmodule(dbSubmodule);

    final RepositoryHandler repositoryHandler = mock(RepositoryHandler.class);
    when(repositoryHandler.getArtifact(dbArtifact.getGavc())).thenReturn(dbArtifact);
    when(repositoryHandler.getArtifact(dbArtifact2.getGavc())).thenReturn(dbArtifact2);
    when(repositoryHandler.getArtifact(dbThirdParty.getGavc())).thenReturn(dbThirdParty);
    when(repositoryHandler.getArtifact(dbThirdParty2.getGavc())).thenReturn(dbThirdParty2);

    final ModelMapper modelMapper = new ModelMapper(repositoryHandler);
    final Module module = modelMapper.getModule(dbModule);

    assertEquals(dbModule.getName(), module.getName());
    assertEquals(dbModule.getVersion(), module.getVersion());
    assertEquals(1, module.getArtifacts().size());
    assertEquals(dbArtifact.getGavc(), module.getArtifacts().iterator().next().getGavc());
    assertEquals(1, module.getDependencies().size());

    final Dependency thirdParty = module.getDependencies().iterator().next();
    assertEquals(dbThirdParty.getGavc(), thirdParty.getTarget().getGavc());
    assertEquals(Scope.COMPILE, thirdParty.getScope());
    assertEquals(dbModule.getName(), thirdParty.getSourceName());
    assertEquals(dbModule.getVersion(), thirdParty.getSourceVersion());

    assertEquals(1, module.getSubmodules().size());
    final Module submodule = module.getSubmodules().iterator().next();

    assertEquals(dbSubmodule.getName(), submodule.getName());
    assertEquals(dbSubmodule.getVersion(), submodule.getVersion());
    assertEquals(1, submodule.getArtifacts().size());
    assertEquals(dbArtifact2.getGavc(), submodule.getArtifacts().iterator().next().getGavc());
    assertEquals(1, submodule.getDependencies().size());
    assertEquals(
        dbThirdParty2.getGavc(),
        submodule.getDependencies().iterator().next().getTarget().getGavc());
    assertEquals(
        dbSubmodule.getName(), submodule.getDependencies().iterator().next().getSourceName());
    assertEquals(
        dbSubmodule.getVersion(), submodule.getDependencies().iterator().next().getSourceVersion());
    assertEquals(Scope.PROVIDED, submodule.getDependencies().iterator().next().getScope());
  }