Пример #1
0
  @Test
  public void testCreateArtifact() throws Exception {
    prepare(CreateArtifactCommand.class);

    // failure tests
    pushToOutput("createArtifact --type ComplexTypeDeclaration --name FooName");
    Assert.assertTrue(
        stream.toString().contains("The artifact you are trying to create is a derived artifact"));
    pushToOutput("createArtifact --type XmlDocument --name FooName");
    Assert.assertTrue(
        stream.toString().contains("The artifact you are trying to create is a document artifact"));

    // the initial create needs to return an artifact, its then used to set the context
    BaseArtifactType extendedArtifact =
        ArtifactType.ExtendedArtifactType("FooType").newArtifactInstance();
    extendedArtifact.setName("FooName");
    Mockito.when(clientMock.createArtifact(Mockito.any(BaseArtifactType.class)))
        .thenReturn(extendedArtifact);

    // success tests
    pushToOutput("createArtifact --type FooType --name FooName --description FooDescription");
    ArgumentCaptor<BaseArtifactType> artifact = ArgumentCaptor.forClass(BaseArtifactType.class);
    Mockito.verify(clientMock, Mockito.times(1)).createArtifact(artifact.capture());
    Assert.assertEquals("FooName", artifact.getValue().getName());
    Assert.assertEquals("FooDescription", artifact.getValue().getDescription());
    Assert.assertEquals("FooType", ArtifactType.valueOf(artifact.getValue()).getExtendedType());

    // ensure it was set as the current artifact in the context
    Assert.assertEquals("FooName", getAeshContext().getCurrentArtifact().getName());
  }
 @Override
 public ArtifactType detect(ArtifactContent content) {
   // VDB manifest
   if (VdbManifest.FILE_NAME.equals(content.getFilename())) {
     return ArtifactType.valueOf(TeiidArtifactType.VDB_MANIFEST.extendedType(), true);
   }
   // Teiid models
   if (content.getFilename().endsWith(TeiidModel.FILE_EXT)) {
     return ArtifactType.valueOf(TeiidArtifactType.MODEL.extendedType(), true);
   }
   // VDB configuration info def
   if (Vdb.CONFIGURATION_INFO_FILE_NAME.equals(content.getFilename())) {
     return ArtifactType.valueOf(Vdb.VdbExtendedType.CONFIG_INFO.extendedType(), true);
   }
   return null;
 }
 @Override
 public ArtifactType detect(ArtifactContent content, ArchiveContext archiveContext) {
   if (archiveContext.isExpandedFromArchive()) {
     return detect(content);
   } else if (archiveContext.hasArchiveEntry("META-INF/vdb.xml")) {
     return ArtifactType.valueOf(Vdb.ARTIFACT_TYPE, true);
   }
   return null;
 }
 /**
  * Adds an XML document.
  *
  * @throws Exception
  */
 protected BaseArtifactType addXmlDoc() throws Exception {
   String artifactFileName = "PO.xml";
   InputStream is = this.getClass().getResourceAsStream("/sample-files/core/" + artifactFileName);
   try {
     ArtificerAtomApiClient client = client();
     return client.uploadArtifact(ArtifactType.XmlDocument(), is, artifactFileName);
   } finally {
     IOUtils.closeQuietly(is);
   }
 }
Пример #5
0
  @Test
  public void testUploadArtifact() throws Exception {
    prepare(UploadArtifactCommand.class);

    // failure tests
    pushToOutput("uploadArtifact --type XmlDocument nope.xml");
    Assert.assertTrue(stream.toString().contains("File not found"));

    // the initial upload needs to return an artifact, since the command later modifies its custom
    // properties and updates
    BaseArtifactType xmlDocument = ArtifactType.XmlDocument().newArtifactInstance();
    Mockito.when(
            clientMock.uploadArtifact(
                Mockito.any(ArtifactType.class),
                Mockito.any(InputStream.class),
                Mockito.anyString()))
        .thenReturn(xmlDocument);

    // success tests
    pushToOutput(
        "uploadArtifact --type XmlDocument --name FooName --description FooDescription PO.xml");

    ArgumentCaptor<ArtifactType> artifactType = ArgumentCaptor.forClass(ArtifactType.class);
    ArgumentCaptor<String> fileName = ArgumentCaptor.forClass(String.class);
    Mockito.verify(clientMock, Mockito.times(1))
        .uploadArtifact(artifactType.capture(), Mockito.any(InputStream.class), fileName.capture());
    Assert.assertEquals(ArtifactType.XmlDocument(), artifactType.getValue());
    Assert.assertEquals("PO.xml", fileName.getValue());

    ArgumentCaptor<BaseArtifactType> artifact = ArgumentCaptor.forClass(BaseArtifactType.class);
    Mockito.verify(clientMock, Mockito.times(1)).updateArtifactMetaData(artifact.capture());
    Assert.assertEquals("FooName", artifact.getValue().getName());
    Assert.assertEquals("FooDescription", artifact.getValue().getDescription());

    Assert.assertTrue(stream.toString().contains("Successfully uploaded the artifact"));

    // ensure it was set as the current artifact in the context
    Assert.assertEquals("FooName", getAeshContext().getCurrentArtifact().getName());
  }
Пример #6
0
  /**
   * Main.
   *
   * @param args
   */
  public static void main(String[] args) throws Exception {
    System.out.println("\n*** Running Artificer Query Demo ***\n");

    String endpoint = System.getProperty("artificer.endpoint");
    String username = System.getProperty("artificer.auth.username");
    String password = System.getProperty("artificer.auth.password");
    if (endpoint == null || endpoint.trim().length() == 0) {
      endpoint = DEFAULT_ENDPOINT;
    }
    if (username == null || username.trim().length() == 0) {
      username = DEFAULT_USER;
    }
    if (password == null || password.trim().length() == 0) {
      password = DEFAULT_PASSWORD;
    }
    System.out.println("Artificer Endpoint: " + endpoint);
    System.out.println("Artificer User: "******"/s-ramp[@from-demo = ?]")
            .parameter(PropertyDemo.class.getSimpleName())
            .count(1)
            .query();
    if (rs.size() > 0) {
      System.out.println("It looks like you already ran this demo!");
      System.out.println("I'm going to quit, because I don't want to clutter up");
      System.out.println("your repository with duplicate stuff.");
      System.exit(1);
    }

    // Before we do anything else, we need to upload some artifacts to the
    // Artificer repository.
    ArtifactType type = ArtifactType.valueOf("Document");
    System.out.print("Uploading two artifacts...");
    BaseArtifactType artifact1 =
        client.uploadArtifact(
            type,
            PropertyDemo.class.getResourceAsStream("property-demo-doc-1.txt"),
            "property-demo-doc-1.txt");
    BaseArtifactType artifact2 =
        client.uploadArtifact(
            type,
            PropertyDemo.class.getResourceAsStream("property-demo-doc-2.txt"),
            "property-demo-doc-2.txt");
    System.out.println("uploaded.");

    // And then we can change their names if we want!
    artifact1.setName("property-demo-document-1.txt");
    artifact2.setName("property-demo-document-2.txt");

    // Now, we can modify the artifacts by adding some custom properties to them.
    ArtificerModelUtils.setCustomProperty(artifact1, "property-demo", "true");
    ArtificerModelUtils.setCustomProperty(artifact1, "artifact-num", "one");
    ArtificerModelUtils.setCustomProperty(artifact1, "hello", "world");
    ArtificerModelUtils.setCustomProperty(artifact2, "property-demo", "true");
    ArtificerModelUtils.setCustomProperty(artifact2, "artifact-num", "two");
    ArtificerModelUtils.setCustomProperty(artifact2, "foo", "bar");

    // Also tag these artifacts as coming from this demo.
    ArtificerModelUtils.setCustomProperty(
        artifact1, "from-demo", PropertyDemo.class.getSimpleName());
    ArtificerModelUtils.setCustomProperty(
        artifact2, "from-demo", PropertyDemo.class.getSimpleName());

    // And now update both artifacts so that the repository knows about these
    // new properties.
    System.out.print("Updating (meta-data for) both artifacts...");
    client.updateArtifactMetaData(artifact1);
    client.updateArtifactMetaData(artifact2);
    System.out.println("updated.");

    // Next, fetch the artifact meta-data from the server and make sure the properties
    // we set above are really there.
    System.out.print("Re-fetching (meta-data for) both artifacts...");
    BaseArtifactType metaData1 = client.getArtifactMetaData(type, artifact1.getUuid());
    BaseArtifactType metaData2 = client.getArtifactMetaData(type, artifact2.getUuid());
    System.out.println("fetched.");
    if (metaData1.getProperty().size() < 3) {
      System.out.println("Properties not found on artifact 1!  Oh noes!");
      System.exit(1);
    } else {
      System.out.println("All properties accounted for (artifact 1)!");
    }
    if (metaData2.getProperty().size() < 3) {
      System.out.println("Properties not found on artifact 2!  Oh noes!");
      System.exit(1);
    } else {
      System.out.println("All properties accounted for (artifact 2)!");
    }

    // Now we know that adding properties works.  Note that of course you can also
    // remove properties and change their values, and that will work the same way
    // (just remember to call updateArtifactMetaData after you make changes).

    // The next thing I want to show you is how to query for artifacts in the
    // repository by their properties.  You can query by either base property or
    // by custom user property.
    String q = "/s-ramp/core/Document[@name = 'property-demo-document-1.txt']";
    QueryResultSet resultSet = client.query(q);
    if (resultSet.size() == 0) {
      System.out.println("Failed to find property-demo-document-1.txt!");
      System.exit(1);
    }
    // Find all of the documents with the 'property-demo' property set to 'true' (should
    // be all of them)
    q = "/s-ramp/core/Document[@property-demo = 'true']";
    resultSet = client.query(q);
    if (resultSet.size() == 0) {
      System.out.println("Failed to find document(s) with @property-demo set to 'true'!");
      System.exit(1);
    } else {
      System.out.println("Search 1 succeeded.");
    }
    long total = resultSet.size();
    // Find only the ones with 'artifact-num' set to 'one' (should be half of them)
    q = "/s-ramp/core/Document[@artifact-num = 'one']";
    resultSet = client.query(q);
    if (resultSet.size() == 0) {
      System.out.println("Failed to find document(s) with @artifact-num set to 'one'!");
      System.exit(1);
    }
    long ones = resultSet.size();
    if (!(total / 2 == ones)) {
      System.out.println("The wrong number of documents with @artifact-num set to 'one' found!");
      System.exit(1);
    } else {
      System.out.println("Search 2 succeeded.");
    }

    // All done.
    System.out.println("\n*** Demo Completed Successfully ***\n\n");
    Thread.sleep(3000);
  }