Search in sources :

Example 1 with Toolkit

use of com.ibm.streamsx.rest.build.Toolkit in project streamsx.topology by IBMStreams.

the class ToolkitAPITest method testGetDependencies.

// Test getting the dependencies of a toolkit.
@Test
public void testGetDependencies() throws Exception {
    // Games depends on both cards and bingo.
    Toolkit bingo = connection.uploadToolkit(bingo0Path);
    assertNotNull(bingo);
    Toolkit cards = connection.uploadToolkit(cardsPath);
    assertNotNull(cards);
    Toolkit games = connection.uploadToolkit(gamesPath);
    assertNotNull(games);
    // bingo and cards have no dependencies
    assertEquals(0, bingo.getDependencies().size());
    assertEquals(0, cards.getDependencies().size());
    List<Toolkit.Dependency> gamesDependencies = games.getDependencies();
    assertEquals(2, gamesDependencies.size());
    assertEquals(bingoToolkitName, gamesDependencies.get(0).getName());
    assertEquals("[1.0.0,2.0.0)", gamesDependencies.get(0).getVersion());
    assertEquals(cardsToolkitName, gamesDependencies.get(1).getName());
    assertEquals("[1.0.0,1.1.0)", gamesDependencies.get(1).getVersion());
    assertTrue(games.delete());
    assertTrue(cards.delete());
    assertTrue(bingo.delete());
}
Also used : Toolkit(com.ibm.streamsx.rest.build.Toolkit) Test(org.junit.Test)

Example 2 with Toolkit

use of com.ibm.streamsx.rest.build.Toolkit in project streamsx.topology by IBMStreams.

the class ToolkitAPITest method testPostMultipleVersions.

// Test posting different versions of a toolkit.  Posting a version
// equal to one that is currently deployed should fail,
// but posting a different version should succeed.
@Test
public void testPostMultipleVersions() throws Exception {
    List<Toolkit> toolkits = connection.getToolkits();
    // First post version 1.0.1
    Toolkit bingo1 = connection.uploadToolkit(bingo1Path);
    assertNotNull(bingo1);
    waitForToolkit(bingoToolkitName, Optional.of(bingo1Version));
    // Post version 1.0.1 again.  It should return Null
    assertNull(connection.uploadToolkit(bingo1Path));
    // Post verison 1.0.0.  It should succeed as it does not match any
    // existing version.
    Toolkit bingo0 = connection.uploadToolkit(bingo0Path);
    assertNotNull(bingo0);
    waitForToolkit(bingoToolkitName, Optional.of(bingo0Version));
    // Version 1.0.1 should still exist
    assertToolkitExists(bingoToolkitName, Optional.of(bingo1Version));
    assertToolkitNotExists(bingoToolkitName, Optional.of(bingo2Version));
    // Post version 1.0.2.  All three version continue to exist.
    Toolkit bingo2 = connection.uploadToolkit(bingo2Path);
    assertNotNull(bingo2);
    waitForToolkit(bingoToolkitName, Optional.of(bingo2Version));
    assertToolkitExists(bingoToolkitName, Optional.of(bingo0Version));
    assertToolkitExists(bingoToolkitName, Optional.of(bingo1Version));
    assertTrue(bingo0.delete());
    assertTrue(bingo1.delete());
    assertTrue(bingo2.delete());
}
Also used : Toolkit(com.ibm.streamsx.rest.build.Toolkit) Test(org.junit.Test)

Example 3 with Toolkit

use of com.ibm.streamsx.rest.build.Toolkit in project streamsx.topology by IBMStreams.

the class ToolkitAPITest method testDeleteToolkit.

@Test
public void testDeleteToolkit() throws Exception {
    Toolkit bingo = connection.uploadToolkit(bingo0Path);
    assertNotNull(bingo);
    assertEquals(bingo.getName(), bingoToolkitName);
    assertEquals(bingo.getVersion(), bingo0Version);
    waitForToolkit(bingo.getName(), Optional.of(bingo.getVersion()));
    // deleting once should succeed.
    assertTrue(bingo.delete());
    // Verify that it has been removed
    assertToolkitNotExists(bingoToolkitName);
    // deleting again should fail.
    assertFalse(bingo.delete());
    // RESTException if we try to get index on a deleted toolkit.
    try {
        bingo.getIndex();
        fail("Expected RESTException");
    } catch (RESTException e) {
    }
    // Post it again, then find it in the list of toolkits and delete
    // it from the Toolkit object from the list.
    bingo = connection.uploadToolkit(bingo0Path);
    assertNotNull(bingo);
    assertEquals(bingo.getName(), bingoToolkitName);
    assertEquals(bingo.getVersion(), bingo0Version);
    List<Toolkit> foundToolkits = findMatchingToolkits(bingoToolkitName, Optional.of(bingo0Version));
    assertEquals(foundToolkits.size(), 1);
    assertTrue(foundToolkits.get(0).delete());
}
Also used : RESTException(com.ibm.streamsx.rest.RESTException) Toolkit(com.ibm.streamsx.rest.build.Toolkit) Test(org.junit.Test)

Example 4 with Toolkit

use of com.ibm.streamsx.rest.build.Toolkit in project streamsx.topology by IBMStreams.

the class ToolkitAPITest method testGetTookit.

// Test getting a toolkit by id.
@Test
public void testGetTookit() throws Exception {
    Toolkit bingo = connection.uploadToolkit(bingo1Path);
    assertNotNull(bingo);
    waitForToolkit(bingoToolkitName, Optional.of(bingo1Version));
    Toolkit found = connection.getToolkit(bingo.getId());
    assertNotNull(found);
    assertEquals(bingoToolkitName, found.getName());
    assertEquals(bingo1Version, found.getVersion());
    assertEquals("4.2", found.getRequiredProductVersion());
    assertEquals("toolkit", found.getResourceType());
    // We don't know what value this attribute will have, but it should
    // have a value
    assertNotNull(found.getPath());
    // The ID is 'streams-toolkits'/name-version
    String toolkitId = "streams-toolkits/" + bingoToolkitName + "-" + bingo1Version;
    found = connection.getToolkit(toolkitId);
    assertNotNull(found);
    // Using just the name fails
    toolkitId = "streams-toolkits/" + bingoToolkitName;
    try {
        found = connection.getToolkit(toolkitId);
        fail("Expected RESTException");
    } catch (RESTException e) {
    }
}
Also used : RESTException(com.ibm.streamsx.rest.RESTException) Toolkit(com.ibm.streamsx.rest.build.Toolkit) Test(org.junit.Test)

Example 5 with Toolkit

use of com.ibm.streamsx.rest.build.Toolkit in project streamsx.topology by IBMStreams.

the class ToolkitAPITest method testGetIndex.

@Test
public void testGetIndex() throws Exception {
    Toolkit bingo = connection.uploadToolkit(bingo0Path);
    assertNotNull(bingo);
    assertEquals(bingoToolkitName, bingo.getName());
    assertEquals(bingo0Version, bingo.getVersion());
    String index = bingo.getIndex();
    assertNotNull(index);
    // try parsing the xml, and verify some of the content.
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    assertTrue(factory.isNamespaceAware());
    DocumentBuilder builder = factory.newDocumentBuilder();
    InputStream is = new ByteArrayInputStream(index.getBytes("UTF-8"));
    Document doc = builder.parse(is);
    NodeList toolkitModelElementList = doc.getDocumentElement().getElementsByTagNameNS("http://www.ibm.com/xmlns/prod/streams/spl/toolkit", "toolkit");
    assertNotNull(toolkitModelElementList);
    assertEquals(1, toolkitModelElementList.getLength());
    Node toolkitElementNode = toolkitModelElementList.item(0);
    assertTrue(toolkitElementNode.hasAttributes());
    NamedNodeMap attributes = toolkitElementNode.getAttributes();
    assertNotNull(attributes);
    Node nameNode = attributes.getNamedItem("name");
    assertNotNull(nameNode);
    assertEquals(bingoToolkitName, nameNode.getNodeValue());
    Node versionNode = attributes.getNamedItem("version");
    assertNotNull(versionNode);
    assertEquals(bingo0Version, versionNode.getNodeValue());
    assertTrue(bingo.delete());
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) NamedNodeMap(org.w3c.dom.NamedNodeMap) DocumentBuilder(javax.xml.parsers.DocumentBuilder) ByteArrayInputStream(java.io.ByteArrayInputStream) DirectoryZipInputStream(com.ibm.streamsx.rest.internal.DirectoryZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Toolkit(com.ibm.streamsx.rest.build.Toolkit) Document(org.w3c.dom.Document) Test(org.junit.Test)

Aggregations

Toolkit (com.ibm.streamsx.rest.build.Toolkit)7 Test (org.junit.Test)6 RESTException (com.ibm.streamsx.rest.RESTException)2 DirectoryZipInputStream (com.ibm.streamsx.rest.internal.DirectoryZipInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HashSet (java.util.HashSet)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 After (org.junit.After)1 Document (org.w3c.dom.Document)1 NamedNodeMap (org.w3c.dom.NamedNodeMap)1 Node (org.w3c.dom.Node)1 NodeList (org.w3c.dom.NodeList)1