コード例 #1
0
  @Test
  public void testAddResourceWithMultipleContent() throws Exception {
    // Add a resource from XML
    RepositoryReader reader = getRepositoryReader("xml/repository-testB.xml");
    storage.addResource(reader.nextResource());

    Requirement req =
        new DefaultRequirementBuilder(IdentityNamespace.IDENTITY_NAMESPACE, "resA")
            .getRequirement();
    Collection<Capability> providers = storage.findProviders(req);
    Assert.assertNotNull(providers);
    Assert.assertEquals(1, providers.size());

    Capability cap = providers.iterator().next();
    Assert.assertEquals("resA", cap.getAttribute(IdentityNamespace.IDENTITY_NAMESPACE));

    Resource resource = cap.getResource();
    verifyDefaultContent(resource);

    InputStream input = resource.adapt(ResourceContent.class).getContent();
    String digest = RepositoryContentHelper.getDigest(input);
    Assert.assertNotNull("RepositoryContent not null", input);
    input.close();

    List<Capability> ccaps = resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE);
    Assert.assertEquals(2, ccaps.size());
    ContentCapability ccap = ccaps.get(0).adapt(ContentCapability.class);
    Assert.assertEquals(digest, ccap.getDigest());
    Assert.assertEquals("application/java-archive", ccap.getMimeType());
    Assert.assertEquals(new Long(392), ccap.getSize());
    File contentFile = new File(ccap.getContentURL().getPath()).getCanonicalFile();
    Assert.assertTrue("File exists: " + contentFile, contentFile.exists());
    Assert.assertTrue(
        "Path starts with: " + storageDir.getPath(),
        contentFile.getPath().startsWith(storageDir.getPath()));

    ccap = ccaps.get(1).adapt(ContentCapability.class);
    Assert.assertFalse(digest.equals(ccap.getDigest()));
    Assert.assertEquals("text/plain", ccap.getMimeType());
    Assert.assertEquals(new Long("some text".length()), ccap.getSize());
    contentFile = new File(ccap.getContentURL().getPath()).getCanonicalFile();
    Assert.assertTrue("File exists: " + contentFile, contentFile.exists());
    Assert.assertTrue(
        "Path starts with: " + storageDir.getPath(),
        contentFile.getPath().startsWith(storageDir.getPath()));

    BufferedReader br = new BufferedReader(new FileReader(contentFile));
    Assert.assertEquals("some text", br.readLine());
    br.close();
  }
コード例 #2
0
  @Test
  public void testCustomNamespace() throws Exception {

    // Add a resource from XML
    RepositoryReader reader = getRepositoryReader("xml/repository-testA.xml");
    Resource resource = storage.addResource(reader.nextResource());

    verifyResource(resource);
    verifyProviders(storage);

    List<Capability> allcaps = resource.getCapabilities(null);
    Assert.assertEquals(3, allcaps.size());

    Requirement req =
        new DefaultRequirementBuilder("custom.namespace", "custom.value").getRequirement();
    Collection<Capability> providers = storage.findProviders(req);
    Assert.assertEquals("One provider", 1, providers.size());

    req = new DefaultRequirementBuilder("custom.namespace", "bogus").getRequirement();
    providers = storage.findProviders(req);
    Assert.assertEquals("No provider", 0, providers.size());
  }
コード例 #3
0
  private void verifyDefaultContent(Resource resource) throws Exception {
    InputStream input = resource.adapt(ResourceContent.class).getContent();
    String digest = RepositoryContentHelper.getDigest(input);
    Assert.assertNotNull("RepositoryContent not null", input);
    input.close();

    Capability cap = resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE).get(0);
    ContentCapability ccap = cap.adapt(ContentCapability.class);
    Assert.assertEquals(digest, ccap.getDigest());
    Assert.assertEquals(digest, cap.getAttribute(ContentNamespace.CONTENT_NAMESPACE));
    Assert.assertEquals("application/java-archive", ccap.getMimeType());
    Assert.assertEquals(
        "application/java-archive", cap.getAttribute(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE));
    Assert.assertEquals(new Long(392), ccap.getSize());
    Assert.assertEquals(
        new Long(392), cap.getAttribute(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE));
    URL contentURL = (URL) ccap.getAttribute(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
    File contentFile = new File(contentURL.getPath()).getCanonicalFile();
    Assert.assertTrue("File exists: " + contentFile, contentFile.exists());
    Assert.assertTrue(
        "Path starts with: " + storageDir.getPath(),
        contentFile.getPath().startsWith(storageDir.getPath()));
  }
コード例 #4
0
 private void verifyResource(Resource resource) throws Exception {
   verifyDefaultContent(resource);
   Assert.assertEquals(3, resource.getCapabilities(null).size());
 }