コード例 #1
0
 @Test
 public void testLoadRepository() throws IOException {
   ArtifactDescriptorPersister persistenceHandler =
       new XmlArtifactDescriptorPersister(
           new XMLRepositoryCodec(), DUMMY_REPOSITORY_NAME, new File(repositories, TEST_REPO_ONE));
   persistenceHandler.persistArtifactDescriptors(ARTEFACTS);
   Set<RepositoryAwareArtifactDescriptor> artefacts2 = persistenceHandler.loadArtifacts();
   assertEquals(ARTEFACTS, artefacts2);
 }
コード例 #2
0
  @Test
  public void roundTripWithAttributeWithEmptyValue() throws IOException {
    File outputFile = new File(repositories, "round-trip");
    assertFalse(outputFile.exists());
    ArtifactDescriptorPersister persister =
        new XmlArtifactDescriptorPersister(
            new XMLRepositoryCodec(), DUMMY_REPOSITORY_NAME, outputFile);

    RepositoryAwareArtifactDescriptor descriptor =
        new RepositoryAwareArtifactDescriptor() {

          public Set<Attribute> getAttribute(String name) {
            return null;
          }

          public Set<Attribute> getAttributes() {
            Set<Attribute> attributes = new HashSet<Attribute>();
            attributes.add(
                new Attribute() {

                  public String getKey() {
                    return "the-key";
                  }

                  public Map<String, Set<String>> getProperties() {
                    return new HashMap<String, Set<String>>();
                  }

                  public String getValue() {
                    return "";
                  }
                });
            return attributes;
          }

          public String getName() {
            return "bar";
          }

          public String getType() {
            return "foo";
          }

          public java.net.URI getUri() {
            return java.net.URI.create("foo://bar");
          }

          public Version getVersion() {
            return new Version(1, 0, 0);
          }

          public String getFilename() {
            return null;
          }

          public String getRepositoryName() {
            return null;
          }
        };

    persister.persistArtifactDescriptors(
        new HashSet<RepositoryAwareArtifactDescriptor>(Arrays.asList(descriptor)));

    Set<RepositoryAwareArtifactDescriptor> descriptors = persister.loadArtifacts();
    assertEquals(1, descriptors.size());

    ArtifactDescriptor outputDescriptor = descriptors.iterator().next();
    assertEquals("foo", outputDescriptor.getType());
    assertEquals("bar", outputDescriptor.getName());
    assertEquals(new Version(1, 0, 0), outputDescriptor.getVersion());
    assertEquals(java.net.URI.create("foo://bar"), outputDescriptor.getUri());

    Set<Attribute> attributes = descriptors.iterator().next().getAttributes();
    assertEquals(5, attributes.size());
  }