/**
   * Creates a WSDL artifact in the s-ramp repository.
   *
   * @return the new artifact
   * @throws Exception
   */
  private XmlDocument createXmlArtifact() throws Exception {
    String artifactFileName = "PO.xml";
    InputStream contentStream =
        this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);
    try {
      ClientRequest request = clientRequest("/s-ramp/core/XmlDocument");
      request.header("Slug", artifactFileName);
      request.body("application/xml", contentStream);

      ClientResponse<Entry> response = request.post(Entry.class);

      Entry entry = response.getEntity();
      Assert.assertEquals(artifactFileName, entry.getTitle());
      BaseArtifactType arty = ArtificerAtomUtils.unwrapSrampArtifact(entry);
      Assert.assertTrue(arty instanceof XmlDocument);
      XmlDocument doc = (XmlDocument) arty;
      Assert.assertEquals(artifactFileName, doc.getName());
      Long size = doc.getContentSize();
      Assert.assertTrue(size >= 825L);
      Assert.assertEquals("application/xml", doc.getContentType());
      return doc;
    } finally {
      IOUtils.closeQuietly(contentStream);
    }
  }
Пример #2
0
 private Entry wrapInEntry(E element) {
   try {
     Entry entry = new Entry();
     entry.setTitle(getEntryTitle(element));
     entry.setId(getEntryId(element));
     entry.setUpdated(getEntryUpdated(element));
     Content content = new Content();
     content.setJAXBObject(element);
     entry.setContent(content);
     return entry;
   } catch (URISyntaxException e) {
     throw new RuntimeException(e);
   }
 }
 @Override
 public void add(Entry entry) {
   try {
     Content content = entry.getContent();
     Notification notificatie;
     notificatie = content.getJAXBObject(Notification.class);
     notificatie.setUpdated(new Date());
     notificaties.add(notificatie);
   } catch (JAXBException e) {
     throw new RuntimeException(e);
   }
 }
Пример #4
0
  @GET
  @Produces(MediaType.APPLICATION_ATOM_XML)
  public Feed getFeed() throws URISyntaxException, MalformedURLException {
    log.info("appel feed stories sur baseuri : ");
    if (rq != null) {
      log.info("le request available : " + rq.getContextPath());
    } else {
      return null;
    }
    // gestion de l'adresse
    URL u = new URL("http", rq.getServerName(), rq.getLocalPort(), rq.getContextPath());
    String adresse = u.toExternalForm();
    log.info("uri base : " + u.toExternalForm());

    // gestion des histoires
    Feed feed = new Feed();
    feed.setId(new URI(adresse + "/stories.html"));
    feed.setUpdated(new Date());
    feed.setTitle("Listes histoires");
    feed.getAuthors().add(new Person("Play Writers"));

    // boucle sur chaque histoires
    List<Story> ls = storyList.getStoriesForFeed(20);
    String baseSto = "/stories/story/";
    for (Story s : ls) {
      // construction du lien de l'histoire
      Link link = new Link();
      link.setTitle(s.getStoTitle());
      link.setHref(new URI(adresse + baseSto + s.getStoURL() + ".html"));

      // construction de l'entree
      Entry entry = new Entry();
      entry.setTitle(s.getStoTitle());
      entry.setPublished(s.getStoDate());
      entry.setUpdated(s.getStoDateUpd());

      // ajout du lien dans l'entree
      entry.getLinks().add(link);
      Content content = new Content();
      content.setType(MediaType.TEXT_HTML_TYPE);
      content.setText(s.getStoSyn());
      entry.setContent(content);

      // ajout de l'entree dans le flux de sortie
      feed.getEntries().add(entry);
    }
    return feed;
  }
  @Test
  public void testZipPackage() throws Exception {
    ArtificerArchive archive = null;
    InputStream xsd1ContentStream = null;
    InputStream xsd2ContentStream = null;
    File zipFile = null;
    InputStream zipStream = null;
    ClientRequest request = null;

    try {
      // Create a test s-ramp archive
      archive = new ArtificerArchive();
      xsd1ContentStream = this.getClass().getResourceAsStream("/sample-files/xsd/PO.xsd");
      BaseArtifactType metaData = new XsdDocument();
      metaData.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
      metaData.setName("PO.xsd");
      archive.addEntry("schemas/PO.xsd", metaData, xsd1ContentStream);
      xsd2ContentStream = this.getClass().getResourceAsStream("/sample-files/xsd/XMLSchema.xsd");
      metaData = new XsdDocument();
      metaData.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
      metaData.setName("XMLSchema.xsd");
      metaData.setVersion("1.0");
      archive.addEntry("schemas/XMLSchema.xsd", metaData, xsd2ContentStream);

      zipFile = archive.pack();
      zipStream = FileUtils.openInputStream(zipFile);

      // Now POST the archive to the s-ramp repository (POST to /s-ramp as application/zip)
      request = clientRequest("/s-ramp");
      request.body(MediaType.APPLICATION_ZIP, zipStream);
      ClientResponse<MultipartInput> clientResponse = request.post(MultipartInput.class);

      // Process the response - it should be multipart/mixed with each part being
      // itself an http response with a code, content-id, and an s-ramp atom entry
      // body
      MultipartInput response = clientResponse.getEntity();
      List<InputPart> parts = response.getParts();
      Map<String, BaseArtifactType> artyMap = new HashMap<String, BaseArtifactType>();
      for (InputPart part : parts) {
        String id = part.getHeaders().getFirst("Content-ID");
        HttpResponseBean rbean = part.getBody(HttpResponseBean.class, null);
        Assert.assertEquals(201, rbean.getCode());
        Entry entry = (Entry) rbean.getBody();
        BaseArtifactType artifact = ArtificerAtomUtils.unwrapSrampArtifact(entry);
        artyMap.put(id, artifact);
      }

      Assert.assertTrue(artyMap.keySet().contains("<schemas/PO.xsd@package>"));
      Assert.assertTrue(artyMap.keySet().contains("<schemas/XMLSchema.xsd@package>"));

      // Assertions for artifact 1
      BaseArtifactType arty = artyMap.get("<schemas/PO.xsd@package>");
      Assert.assertNotNull(arty);
      Assert.assertEquals("PO.xsd", arty.getName());
      Assert.assertNull(arty.getVersion());

      arty = artyMap.get("<schemas/XMLSchema.xsd@package>");
      Assert.assertNotNull(arty);
      Assert.assertEquals("XMLSchema.xsd", arty.getName());
      Assert.assertEquals("1.0", arty.getVersion());
    } finally {
      IOUtils.closeQuietly(xsd1ContentStream);
      IOUtils.closeQuietly(xsd2ContentStream);
      ArtificerArchive.closeQuietly(archive);
      IOUtils.closeQuietly(zipStream);
      FileUtils.deleteQuietly(zipFile);
    }

    // Verify by querying
    // Do a query using GET with query params
    request = clientRequest("/s-ramp/xsd/XsdDocument");
    ClientResponse<Feed> response = request.get(Feed.class);
    Feed feed = response.getEntity();
    Assert.assertEquals(2, feed.getEntries().size());
    Set<String> artyNames = new HashSet<String>();
    for (Entry entry : feed.getEntries()) {
      artyNames.add(entry.getTitle());
    }
    Assert.assertTrue(artyNames.contains("PO.xsd"));
    Assert.assertTrue(artyNames.contains("XMLSchema.xsd"));
  }
  /**
   * This also tests the zipPackage method of the {@link
   * org.artificer.server.atom.services.BatchResource} class, but it is more thorough. It tests
   * adding new content, updating existing content, etc.
   */
  @Test
  public void testZipPackage_Multi() throws Exception {
    ArtificerArchive archive = null;
    InputStream xsd1ContentStream = null;
    InputStream wsdlContentStream = null;
    File zipFile = null;
    InputStream zipStream = null;
    ClientRequest request = null;

    WsdlDocument wsdlDoc = createWsdlArtifact();
    XmlDocument xmlDoc = createXmlArtifact();

    String xsdUuid = null;
    String wsdlUuid = null;
    String xmlUuid = null;

    try {
      // Create a test s-ramp archive
      archive = new ArtificerArchive();

      // A new XSD document
      xsd1ContentStream = this.getClass().getResourceAsStream("/sample-files/xsd/PO.xsd");
      BaseArtifactType metaData = new XsdDocument();
      metaData.setArtifactType(BaseArtifactEnum.XSD_DOCUMENT);
      metaData.setUuid(UUID.randomUUID().toString()); // will be ignored
      metaData.setName("PO.xsd");
      archive.addEntry("schemas/PO.xsd", metaData, xsd1ContentStream);
      // Update an existing WSDL document (content and meta-data)
      wsdlContentStream =
          this.getClass().getResourceAsStream("/sample-files/wsdl/sample-updated.wsdl");
      metaData = wsdlDoc;
      metaData.setVersion("2.0");
      ArtificerModelUtils.setCustomProperty(metaData, "foo", "bar");
      archive.addEntry("wsdl/sample.wsdl", metaData, wsdlContentStream);
      // Update an existing XML document (meta-data only)
      metaData = xmlDoc;
      metaData.setVersion("3.0");
      ArtificerModelUtils.setCustomProperty(metaData, "far", "baz");
      archive.addEntry("core/PO.xml", metaData, null);

      zipFile = archive.pack();
      zipStream = FileUtils.openInputStream(zipFile);

      // Now POST the archive to the s-ramp repository (POST to /s-ramp as application/zip)
      request = clientRequest("/s-ramp");
      request.body(MediaType.APPLICATION_ZIP, zipStream);
      ClientResponse<MultipartInput> clientResponse = request.post(MultipartInput.class);

      // Process the response - it should be multipart/mixed with each part being
      // itself an http response with a code, content-id, and an s-ramp atom entry
      // body
      MultipartInput response = clientResponse.getEntity();
      List<InputPart> parts = response.getParts();
      Map<String, HttpResponseBean> respMap = new HashMap<String, HttpResponseBean>();
      for (InputPart part : parts) {
        String id = part.getHeaders().getFirst("Content-ID");
        HttpResponseBean rbean = part.getBody(HttpResponseBean.class, null);
        respMap.put(id, rbean);
      }

      // Should be three responses.
      Assert.assertEquals(3, respMap.size());
      Assert.assertTrue(respMap.keySet().contains("<schemas/PO.xsd@package>"));
      Assert.assertTrue(respMap.keySet().contains("<wsdl/sample.wsdl@package>"));
      Assert.assertTrue(respMap.keySet().contains("<core/PO.xml@package>"));

      // Assertions for artifact 1 (PO.xsd)
      HttpResponseBean httpResp = respMap.get("<schemas/PO.xsd@package>");
      Assert.assertEquals(201, httpResp.getCode());
      Assert.assertEquals("Created", httpResp.getStatus());
      Entry entry = (Entry) httpResp.getBody();
      BaseArtifactType artifact = ArtificerAtomUtils.unwrapSrampArtifact(entry);
      Assert.assertEquals("PO.xsd", artifact.getName());
      Assert.assertNull(artifact.getVersion());
      Long size = ((XsdDocument) artifact).getContentSize();
      Assert.assertTrue(size >= 2376L);
      xsdUuid = artifact.getUuid();

      // Assertions for artifact 2 (sample.wsdl)
      httpResp = respMap.get("<wsdl/sample.wsdl@package>");
      Assert.assertEquals(200, httpResp.getCode());
      Assert.assertEquals("OK", httpResp.getStatus());
      entry = (Entry) httpResp.getBody();
      artifact = ArtificerAtomUtils.unwrapSrampArtifact(entry);
      Assert.assertEquals("sample.wsdl", artifact.getName());
      Assert.assertEquals("2.0", artifact.getVersion());
      wsdlUuid = artifact.getUuid();

      // Assertions for artifact 3 (PO.xml)
      httpResp = respMap.get("<core/PO.xml@package>");
      Assert.assertEquals(200, httpResp.getCode());
      Assert.assertEquals("OK", httpResp.getStatus());
      entry = (Entry) httpResp.getBody();
      artifact = ArtificerAtomUtils.unwrapSrampArtifact(entry);
      Assert.assertEquals("PO.xml", artifact.getName());
      Assert.assertEquals("3.0", artifact.getVersion());
      xmlUuid = artifact.getUuid();
    } finally {
      IOUtils.closeQuietly(xsd1ContentStream);
      IOUtils.closeQuietly(wsdlContentStream);
      ArtificerArchive.closeQuietly(archive);
      IOUtils.closeQuietly(zipStream);
      FileUtils.deleteQuietly(zipFile);
    }

    // Verify by querying
    // Do a query using GET with query params
    Map<String, BaseArtifactType> artyMap = new HashMap<String, BaseArtifactType>();
    request = clientRequest("/s-ramp/xsd/XsdDocument");
    ClientResponse<Feed> response = request.get(Feed.class);
    Feed feed = response.getEntity();
    Assert.assertEquals(1, feed.getEntries().size());
    for (Entry entry : feed.getEntries()) {
      String uuid = entry.getId().toString().replace("urn:uuid:", "");
      request = clientRequest("/s-ramp/xsd/XsdDocument/" + uuid);
      BaseArtifactType artifact =
          ArtificerAtomUtils.unwrapSrampArtifact(request.get(Entry.class).getEntity());
      artyMap.put(artifact.getUuid(), artifact);
    }
    request = clientRequest("/s-ramp/wsdl/WsdlDocument");
    response = request.get(Feed.class);
    feed = response.getEntity();
    Assert.assertEquals(1, feed.getEntries().size());
    for (Entry entry : feed.getEntries()) {
      String uuid = entry.getId().toString().replace("urn:uuid:", "");
      request = clientRequest("/s-ramp/wsdl/WsdlDocument/" + uuid);
      BaseArtifactType artifact =
          ArtificerAtomUtils.unwrapSrampArtifact(request.get(Entry.class).getEntity());
      artyMap.put(artifact.getUuid(), artifact);
    }
    request = clientRequest("/s-ramp/core/XmlDocument");
    response = request.get(Feed.class);
    feed = response.getEntity();
    Assert.assertEquals(1, feed.getEntries().size());
    for (Entry entry : feed.getEntries()) {
      String uuid = entry.getId().toString().replace("urn:uuid:", "");
      request = clientRequest("/s-ramp/core/XmlDocument/" + uuid);
      BaseArtifactType artifact =
          ArtificerAtomUtils.unwrapSrampArtifact(request.get(Entry.class).getEntity());
      artyMap.put(artifact.getUuid(), artifact);
    }

    Assert.assertEquals(3, artyMap.size());

    // Assertions for artifact 1 (PO.xsd)
    BaseArtifactType artifact = artyMap.get(xsdUuid);
    Assert.assertEquals("PO.xsd", artifact.getName());
    Assert.assertNull(artifact.getVersion());

    // Assertions for artifact 2 (sample.wsdl)
    artifact = artyMap.get(wsdlUuid);
    Assert.assertEquals("sample.wsdl", artifact.getName());
    Assert.assertEquals("2.0", artifact.getVersion());

    // Assertions for artifact 3 (PO.xml)
    artifact = artyMap.get(xmlUuid);
    Assert.assertEquals("PO.xml", artifact.getName());
    Assert.assertEquals("3.0", artifact.getVersion());
  }