Example usage for javax.activation DataHandler getContent

List of usage examples for javax.activation DataHandler getContent

Introduction

In this page you can find the example usage for javax.activation DataHandler getContent.

Prototype

public Object getContent() throws IOException 

Source Link

Document

Return the data in its preferred Object form.

Usage

From source file:org.wso2.appserver.integration.resources.resource.test.SymlinkTestCase.java

@Test(groups = { "wso2.as" })
public void testAddArtifacts()
        throws ResourceAdminServiceExceptionException, IOException, XPathExpressionException {
    CollectionContentBean collectionContentBean = resourceAdminServiceClient.getCollectionContent("/");
    if (collectionContentBean.getChildCount() > 0) {
        String[] childPath = collectionContentBean.getChildPaths();
        for (int i = 0; i <= childPath.length - 1; i++) {
            if (childPath[i].equalsIgnoreCase(PARENT_PATH)) {
                resourceAdminServiceClient.deleteResource(PARENT_PATH);
            }/*from  w  w w .  java2s .c  o  m*/
        }
    }
    String collectionPath = resourceAdminServiceClient.addCollection("/", "TestAutomation", "", "");
    String authorUserName = resourceAdminServiceClient.getResource(PARENT_PATH)[0].getAuthorUserName();
    assertTrue(asServer.getContextTenant().getContextUser().getUserName().equalsIgnoreCase(authorUserName),
            PARENT_PATH + " creation failure");
    log.info("collection added to " + collectionPath);

    collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH, SYMLINK_PARENT_COLL_NAME, "", "");
    authorUserName = resourceAdminServiceClient.getResource(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME)[0]
            .getAuthorUserName();
    assertTrue(asServer.getContextTenant().getContextUser().getUserName().equalsIgnoreCase(authorUserName),
            PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + " creation failure");
    log.info("collection added to " + collectionPath);

    collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME,
            TEST_COLLECTION1, "", "");
    authorUserName = resourceAdminServiceClient
            .getResource(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION1)[0]
                    .getAuthorUserName();
    assertTrue(asServer.getContextTenant().getContextUser().getUserName().equalsIgnoreCase(authorUserName),
            PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION1 + " creation failure");
    log.info("collection added to " + collectionPath);

    collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME,
            TEST_COLLECTION2, "", "");
    authorUserName = resourceAdminServiceClient
            .getResource(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION2)[0]
                    .getAuthorUserName();
    assertTrue(asServer.getContextTenant().getContextUser().getUserName().equalsIgnoreCase(authorUserName),
            PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION2 + " creation failure");

    log.info("collection added to " + collectionPath);

    String resource = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "AS"
            + File.separator + "txt" + File.separator + "sampleText.txt";

    DataHandler dh = new DataHandler(new URL("file:///" + resource));

    resourceAdminServiceClient.addResource(
            PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION1 + "/" + RESOURCE_NAME,
            "text/html", "txtDesc", dh);

    String text = resourceAdminServiceClient.getTextContent(
            PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION1 + "/" + RESOURCE_NAME);
    String fileText = dh.getContent().toString();

    assertTrue(fileText.equalsIgnoreCase(text), PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/"
            + TEST_COLLECTION1 + "/" + RESOURCE_NAME + " creation failure");
}

From source file:org.wso2.greg.integration.resources.resource.test.AssociationsTestCase.java

@Test(groups = { "wso2.greg" })
public void runSuccessCase()
        throws ResourceAdminServiceExceptionException, IOException, XPathExpressionException {
    log.debug("Running SuccessCase");

    CollectionContentBean collectionContentBean = resourceAdminServiceClient.getCollectionContent("/");

    if (collectionContentBean.getChildCount() > 0) {
        String[] childPath = collectionContentBean.getChildPaths();
        for (int i = 0; i <= childPath.length - 1; i++) {
            if (childPath[i].equalsIgnoreCase(PARENT_PATH)) {
                resourceAdminServiceClient.deleteResource(PARENT_PATH);
            }/*  ww w  . j av a 2  s. c o m*/
        }
    }
    resourceAdminServiceClient.addCollection("/", "TestAutomation", "", "");
    String authorUserName = resourceAdminServiceClient.getResource(PARENT_PATH)[0].getAuthorUserName();
    assertTrue(automationContext.getContextTenant().getContextUser().getUserName()
            .equalsIgnoreCase(authorUserName), PARENT_PATH + " creation failure");
    log.info("collection added to " + PARENT_PATH);

    resourceAdminServiceClient.addCollection(PARENT_PATH, ASSOCIATION_PARENT_COLL_NAME, "", "");
    authorUserName = resourceAdminServiceClient.getResource(PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME)[0]
            .getAuthorUserName();
    assertTrue(automationContext.getContextTenant().getContextUser().getUserName().equalsIgnoreCase(
            authorUserName), PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME + " creation failure");
    log.info("collection added to " + PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME);

    resourceAdminServiceClient.addCollection(PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME, TEST_COLLECTION1,
            "", "");
    authorUserName = resourceAdminServiceClient
            .getResource(PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME + "/" + TEST_COLLECTION1)[0]
                    .getAuthorUserName();

    assertTrue(
            automationContext.getContextTenant().getContextUser().getUserName()
                    .equalsIgnoreCase(authorUserName),
            PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME + "/" + TEST_COLLECTION1 + " creation failure");

    resourceAdminServiceClient.addCollection(PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME, TEST_COLLECTION2,
            "", "");
    authorUserName = resourceAdminServiceClient
            .getResource(PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME + "/" + TEST_COLLECTION2)[0]
                    .getAuthorUserName();
    assertTrue(
            automationContext.getContextTenant().getContextUser().getUserName()
                    .equalsIgnoreCase(authorUserName),
            PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME + "/" + TEST_COLLECTION2 + " creation failure");

    String resource = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "GREG"
            + File.separator + "txt" + File.separator + "sampleText.txt";

    DataHandler dh = new DataHandler(new URL("file:///" + resource));
    resourceAdminServiceClient.addResource(
            PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME + "/" + TEST_COLLECTION1 + "/" + RESOURCE_NAME,
            "text/html", "txtDesc", dh);

    String text = resourceAdminServiceClient.getTextContent(
            PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME + "/" + TEST_COLLECTION1 + "/" + RESOURCE_NAME);
    String fileText = dh.getContent().toString();

    assertTrue(fileText.equalsIgnoreCase(text), PARENT_PATH + "/" + ASSOCIATION_PARENT_COLL_NAME + "/"
            + TEST_COLLECTION1 + "/" + RESOURCE_NAME + " creation failure");
}

From source file:org.wso2.greg.integration.resources.resource.test.NonXMLResourceAddTestCase.java

@Test(groups = { "wso2.greg" })
public void testAddNoneXmlResource()
        throws ResourceAdminServiceExceptionException, IOException, XPathExpressionException {

    //add a collection to the registry
    String collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH, RES_FILE_FOLDER, "",
            "contains Text Res Files");
    String authorUserName = resourceAdminServiceClient.getResource((PARENT_PATH + RES_FILE_FOLDER))[0]
            .getAuthorUserName();// w  ww  .j a va  2s .  com
    assertTrue(automationContext.getContextTenant().getContextUser().getUserName()
            .equalsIgnoreCase(authorUserName), PARENT_PATH + RES_FILE_FOLDER + " creation failure");
    log.info("collection added to " + collectionPath);

    // Changing media type
    collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH, RES_FILE_FOLDER,
            "application/vnd.wso2.esb", "application/vnd.wso2.esb media type collection");
    authorUserName = resourceAdminServiceClient.getResource((PARENT_PATH + RES_FILE_FOLDER))[0]
            .getAuthorUserName();
    assertTrue(automationContext.getContextTenant().getContextUser().getUserName()
            .equalsIgnoreCase(authorUserName), PARENT_PATH + RES_FILE_FOLDER + " updating failure");
    log.info("collection updated in " + collectionPath);

    String resource = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "GREG"
            + File.separator + "txt" + File.separator + "sampleText.txt";

    DataHandler dh = new DataHandler(new URL("file:///" + resource));

    resourceAdminServiceClient.addResource(PARENT_PATH + RES_FILE_FOLDER + "/" + TEXT_FILE_NAME, "text/html",
            "txtDesc", dh);

    String textContent = resourceAdminServiceClient
            .getTextContent(PARENT_PATH + RES_FILE_FOLDER + "/" + TEXT_FILE_NAME);

    assertTrue(dh.getContent().toString().equalsIgnoreCase(textContent),
            "Text file has not been added properly ");
}

From source file:org.wso2.greg.integration.resources.resource.test.RegistryResourceTestCase.java

@Test(groups = { "wso2.greg" }, dependsOnMethods = "testCreateCollection")
public void testAddResourceFromLocalFile() throws IOException, ResourceAdminServiceExceptionException {

    String RESOURCE_NAME = "sampleText.txt";
    String resource = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "GREG"
            + File.separator + "txt" + File.separator + RESOURCE_NAME;

    DataHandler dh = new DataHandler(new URL("file:///" + resource));

    resourceAdminServiceClient.addResource(PARENT_PATH + "/" + WSO2_COLL + "/" + RESOURCE_NAME, "text/html",
            "txtDesc", dh);
    String textContent = resourceAdminServiceClient
            .getTextContent(PARENT_PATH + "/" + WSO2_COLL + "/" + RESOURCE_NAME);

    assertTrue(dh.getContent().toString().equalsIgnoreCase(textContent), "Added resource not found");
    log.info("Resource successfully added to the registry and retrieved contents successfully");

}

From source file:org.wso2.greg.integration.resources.resource.test.SymlinkTestCase.java

@Test(groups = { "wso2.greg" })
public void testAddArtifacts()
        throws ResourceAdminServiceExceptionException, IOException, XPathExpressionException {
    CollectionContentBean collectionContentBean = resourceAdminServiceClient.getCollectionContent("/");
    if (collectionContentBean.getChildCount() > 0) {
        String[] childPath = collectionContentBean.getChildPaths();
        for (int i = 0; i <= childPath.length - 1; i++) {
            if (childPath[i].equalsIgnoreCase(PARENT_PATH)) {
                resourceAdminServiceClient.deleteResource(PARENT_PATH);
            }/*ww  w.ja  v a  2  s  . c  o m*/
        }
    }
    String collectionPath = resourceAdminServiceClient.addCollection("/", "TestAutomation", "", "");
    String authorUserName = resourceAdminServiceClient.getResource(PARENT_PATH)[0].getAuthorUserName();
    assertTrue(automationContext.getContextTenant().getContextUser().getUserName()
            .equalsIgnoreCase(authorUserName), PARENT_PATH + " creation failure");
    log.info("collection added to " + collectionPath);

    collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH, SYMLINK_PARENT_COLL_NAME, "", "");
    authorUserName = resourceAdminServiceClient.getResource(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME)[0]
            .getAuthorUserName();
    assertTrue(automationContext.getContextTenant().getContextUser().getUserName().equalsIgnoreCase(
            authorUserName), PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + " creation failure");
    log.info("collection added to " + collectionPath);

    collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME,
            TEST_COLLECTION1, "", "");
    authorUserName = resourceAdminServiceClient
            .getResource(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION1)[0]
                    .getAuthorUserName();
    assertTrue(
            automationContext.getContextTenant().getContextUser().getUserName()
                    .equalsIgnoreCase(authorUserName),
            PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION1 + " creation failure");
    log.info("collection added to " + collectionPath);

    collectionPath = resourceAdminServiceClient.addCollection(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME,
            TEST_COLLECTION2, "", "");
    authorUserName = resourceAdminServiceClient
            .getResource(PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION2)[0]
                    .getAuthorUserName();
    assertTrue(
            automationContext.getContextTenant().getContextUser().getUserName()
                    .equalsIgnoreCase(authorUserName),
            PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION2 + " creation failure");

    log.info("collection added to " + collectionPath);

    String resource = FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "GREG"
            + File.separator + "txt" + File.separator + "sampleText.txt";

    DataHandler dh = new DataHandler(new URL("file:///" + resource));

    resourceAdminServiceClient.addResource(
            PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION1 + "/" + RESOURCE_NAME,
            "text/html", "txtDesc", dh);

    String text = resourceAdminServiceClient.getTextContent(
            PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/" + TEST_COLLECTION1 + "/" + RESOURCE_NAME);
    String fileText = dh.getContent().toString();

    assertTrue(fileText.equalsIgnoreCase(text), PARENT_PATH + "/" + SYMLINK_PARENT_COLL_NAME + "/"
            + TEST_COLLECTION1 + "/" + RESOURCE_NAME + " creation failure");
}