Package org.drools.guvnor.server.jaxrs.jaxb

Examples of org.drools.guvnor.server.jaxrs.jaxb.Package


    }

    /* Package Creation */
    @Test
    public void testCreatePackageFromJAXB() throws Exception {
        Package p = createTestPackage("TestCreatePackageFromJAXB");
        JAXBContext context = JAXBContext.newInstance(p.getClass());
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.marshal(p, sw);
        String xml = sw.toString();
        URL url = new URL(generateBaseUrl() + "/packages");
View Full Code Here


        System.out.println(GetContent(connection));
    }

    @Test @Ignore
    public void testUpdatePackageFromJAXB() throws Exception {
        Package p = createTestPackage("TestCreatePackageFromJAXB");
        p.setDescription("Updated description.");
        JAXBContext context = JAXBContext.newInstance(p.getClass());
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.marshal(p, sw);
        String xml = sw.toString();
        URL url = new URL(generateBaseUrl() + "/packages/TestCreatePackageFromJAXB");
View Full Code Here

    protected Package createTestPackage(String title) {
        Category c = new Category();
        c.setName("test");

        Package p = new Package();
        PackageMetadata metadata = new PackageMetadata();
        metadata.setCreated(new Date(System.currentTimeMillis()));
        metadata.setUuid(UUID.randomUUID().toString());
        metadata.setLastContributor("awaterma");
        metadata.setLastModified(new Date(System.currentTimeMillis()));

        p.setMetadata(metadata);
        p.setCategory(c);
        p.setCheckInComment("Check in comment for test package.");
        p.setTitle(title);
        p.setDescription("A simple test package with 0 assets.");
        return p;
    }
View Full Code Here

        metadata.setCreated(p.getCreatedDate().getTime());
        metadata.setLastModified(p.getLastModified().getTime());
        metadata.setLastContributor(p.getLastContributor());
        metadata.setState((p.getState() != null) ? p.getState().getName() : "");

        Package ret = new Package();
        ret.setMetadata(metadata);
        ret.setVersion(p.getVersionNumber());
        ret.setTitle(p.getTitle());
        ret.setCheckInComment(p.getCheckinComment());
        ret.setDescription(p.getDescription());

        ret.setBinaryLink(uriInfo.getBaseUriBuilder()
                .path("/packages/{packageName}/binary")
                .build(p.getName()));
        ret.setSourceLink(uriInfo.getBaseUriBuilder()
                .path("/packages/{packageName}/source")
                .build(p.getName()));
        //ret.setSnapshot(p.getSnapshotName());
        ret.setVersion(p.getVersionNumber());
        Iterator<AssetItem> iter = p.getAssets();
        Set<URI> assets = new HashSet<URI>();
        while (iter.hasNext()) {
            AssetItem a = iter.next();
            Asset asset = toAsset(a, uriInfo);
            assets.add(asset.getRefLink());
        }

        ret.setAssets(assets);
        return ret;
    }
View Full Code Here

        metadata.setCreated(p.getCreatedDate().getTime());
        metadata.setLastModified(p.getLastModified().getTime());
        metadata.setLastContributor(p.getLastContributor());
        metadata.setState((p.getState() != null) ? p.getState().getName() : "");

        Package ret = new Package();
        ret.setMetadata(metadata);
        ret.setVersion(p.getVersionNumber());
        ret.setTitle(p.getTitle());
        ret.setCheckInComment(p.getCheckinComment());
        ret.setDescription(p.getDescription());

        UriBuilder builder = uriInfo.getBaseUriBuilder();
        ret.setBinaryLink(
                builder.path("/packages/" + p.getName() + "/binary").build());
        builder = uriInfo.getBaseUriBuilder();
        ret.setSourceLink(
                builder.path("/packages/" + p.getName() + "/source").build());
        //ret.setSnapshot(p.getSnapshotName());
        ret.setVersion(p.getVersionNumber());
        Iterator<AssetItem> iter = p.getAssets();
        Set<URI> assets = new HashSet<URI>();
        while (iter.hasNext()) {
            AssetItem a = iter.next();
            Asset asset = ToAsset(a, uriInfo);
            assets.add(asset.getRefLink());
        }

        ret.setAssets(assets);
        return ret;
    }
View Full Code Here

    public Package createPackageFromDRLAndReturnAsJaxB(InputStream is, @Context UriInfo uriInfo) throws IOException,
            DroolsParserException
    {
        /* Passes the DRL to the FileManagerUtils and has it import the asset as a package */
        String packageName = RepositoryServlet.getFileManager().importClassicDRL (is, null);
        Package p = ToPackage(repository.loadPackage(packageName), uriInfo);
        return p;
    }
View Full Code Here

        connection.setRequestProperty("Accept", MediaType.APPLICATION_XML);
        connection.connect();
        assertEquals (200, connection.getResponseCode());
        assertEquals(MediaType.APPLICATION_XML, connection.getContentType());
        //System.out.println(GetContent(connection));
        Package p = unmarshalPackageXML(connection.getInputStream());
        assertEquals("restPackage1", p.getTitle());
        assertEquals("this is package restPackage1", p.getDescription());
        assertEquals("version3", p.getCheckInComment());
        assertEquals(3, p.getVersion());
        assertEquals("http://localhost:9080/packages/restPackage1/source", p.getSourceLink().toString());
        assertEquals("http://localhost:9080/packages/restPackage1/binary", p.getBinaryLink().toString());
        PackageMetadata pm = p.getMetadata();
        assertEquals("alan_parsons", pm.getLastContributor());
        assertNotNull(pm.getCreated());
        assertNotNull(pm.getUuid());
        assertNotNull(pm.getLastModified());
        Set<URI> assetsURI = p.getAssets();
       
        assertEquals(7, assetsURI.size());
      assertTrue(assetsURI.contains(new URI("http://localhost:9080/packages/restPackage1/assets/drools")));   
      assertTrue(assetsURI.contains(new URI("http://localhost:9080/packages/restPackage1/assets/func")));   
      assertTrue(assetsURI.contains(new URI("http://localhost:9080/packages/restPackage1/assets/myDSL")));   
View Full Code Here

    }

    /* Package Creation */
    @Test
    public void testCreatePackageFromJAXB() throws Exception {
        Package p = createTestPackage("TestCreatePackageFromJAXB");
        p.setCheckInComment("checkincomment for testUpdatePackageFromJAXB");
        JAXBContext context = JAXBContext.newInstance(p.getClass());
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.marshal(p, sw);
        String xml = sw.toString();
        URL url = new URL(generateBaseUrl() + "/packages");
View Full Code Here

    }
   
    @Test
    public void testRenamePackageFromXML() throws Exception {
        //create a package for testing
        Package p = createTestPackage("testRenamePackageFromXML");
        p.setDescription("desc for testRenamePackageFromXML");
        JAXBContext context = JAXBContext.newInstance(p.getClass());
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.marshal(p, sw);
        String xml = sw.toString();
        URL url = new URL(generateBaseUrl() + "/packages");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        String userpassword = "test" + ":" + "password";
        byte[] authEncBytes = Base64.encodeBase64(userpassword.getBytes());
        connection.setRequestProperty("Authorization", "Basic "
                + new String(authEncBytes));
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_XML);
        connection.setRequestProperty("Content-Length", Integer.toString(xml.getBytes().length));
        connection.setUseCaches (false);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestProperty("Accept", MediaType.APPLICATION_XML);
       
        DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
        wr.writeBytes (xml);
        wr.flush ();
        wr.close ();

        assertEquals (200, connection.getResponseCode());
        assertEquals(MediaType.APPLICATION_XML, connection.getContentType());
        //System.out.println(IOUtils.toString(connection.getInputStream()));
        Package result = unmarshalPackageXML(connection.getInputStream());
        assertEquals("testRenamePackageFromXML", result.getTitle());
        assertEquals("desc for testRenamePackageFromXML", result.getDescription());
        assertEquals(new URL(generateBaseUrl() + "/packages/testRenamePackageFromXML/source").toExternalForm(), result.getSourceLink().toString());
        assertEquals(new URL(generateBaseUrl() + "/packages/testRenamePackageFromXML/binary").toExternalForm(), result.getBinaryLink().toString());
        PackageMetadata pm = result.getMetadata();
        assertFalse(pm.isArchived());
        assertNotNull(pm.getCreated());
        assertNotNull(pm.getUuid());
        assertNotNull(pm.getLastModified());
       
View Full Code Here

    }
   
    @Test
    public void testUpdatePackageFromJAXB() throws Exception {
        //create a package for testing
        Package p = createTestPackage("testUpdatePackageFromJAXB");
        p.setDescription("desc for testUpdatePackageFromJAXB");
        JAXBContext context = JAXBContext.newInstance(p.getClass());
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.marshal(p, sw);
        String xml = sw.toString();
        URL url = new URL(generateBaseUrl() + "/packages");
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        String userpassword = "test" + ":" + "password";
        byte[] authEncBytes = Base64.encodeBase64(userpassword.getBytes());
        connection.setRequestProperty("Authorization", "Basic "
                + new String(authEncBytes));
        connection.setRequestMethod("POST");
        connection.setRequestProperty("Content-Type", MediaType.APPLICATION_XML);
        connection.setRequestProperty("Content-Length", Integer.toString(xml.getBytes().length));
        connection.setUseCaches (false);
        connection.setDoInput(true);
        connection.setDoOutput(true);
        connection.setRequestProperty("Accept", MediaType.APPLICATION_XML);
       
        DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
        wr.writeBytes (xml);
        wr.flush ();
        wr.close ();

        assertEquals (200, connection.getResponseCode());
        assertEquals(MediaType.APPLICATION_XML, connection.getContentType());
        //System.out.println(IOUtils.toString(connection.getInputStream()));
        Package result = unmarshalPackageXML(connection.getInputStream());
        assertEquals("testUpdatePackageFromJAXB", result.getTitle());
        assertEquals("desc for testUpdatePackageFromJAXB", result.getDescription());
        assertEquals(new URL(generateBaseUrl() + "/packages/testUpdatePackageFromJAXB/source").toExternalForm(), result.getSourceLink().toString());
        assertEquals(new URL(generateBaseUrl() + "/packages/testUpdatePackageFromJAXB/binary").toExternalForm(), result.getBinaryLink().toString());
        PackageMetadata pm = result.getMetadata();
        assertFalse(pm.isArchived());
        assertNotNull(pm.getCreated());
        assertNotNull(pm.getUuid());
        assertNotNull(pm.getLastModified());
       
       
        //Test update package
        Package p2 = createTestPackage("testUpdatePackageFromJAXB");
        p2.setDescription("update package testUpdatePackageFromJAXB");
        p2.setCheckInComment("checkInComment: update package testUpdatePackageFromJAXB");
        JAXBContext context2 = JAXBContext.newInstance(p2.getClass());
        Marshaller marshaller2 = context2.createMarshaller();
        StringWriter sw2 = new StringWriter();
        marshaller2.marshal(p2, sw2);
        String xml2 = sw2.toString();
        URL url2 = new URL(generateBaseUrl() + "/packages/testUpdatePackageFromJAXB");
        HttpURLConnection connection2 = (HttpURLConnection)url2.openConnection();
        connection2.setRequestProperty("Authorization", "Basic "
                + new String(authEncBytes));
        connection2.setRequestMethod("PUT");
        connection2.setRequestProperty("Content-Type", MediaType.APPLICATION_XML);
        connection2.setRequestProperty("Content-Length", Integer.toString(xml2.getBytes().length));
        connection2.setUseCaches (false);
        //connection2.setDoInput(true);
        connection2.setDoOutput(true);

        OutputStreamWriter out = new OutputStreamWriter(connection2.getOutputStream());
        out.write(xml2);
        out.close();
        connection2.getInputStream();
      
       
        //Verify
        URL url3 = new URL(generateBaseUrl() + "/packages/testUpdatePackageFromJAXB");
        HttpURLConnection connection3 = (HttpURLConnection)url3.openConnection();
        connection3.setRequestProperty("Authorization", "Basic "
                + new String(authEncBytes));
        connection3.setRequestMethod("GET");
        connection3.setRequestProperty("Accept", MediaType.APPLICATION_XML);
        connection3.connect();
        assertEquals (200, connection3.getResponseCode());
        assertEquals(MediaType.APPLICATION_XML, connection3.getContentType());
        //System.out.println("------------------------");
        //System.out.println(IOUtils.toString(connection.getInputStream()));
        Package p3 = unmarshalPackageXML(connection3.getInputStream());
        assertEquals("testUpdatePackageFromJAXB", p3.getTitle());
        assertEquals("update package testUpdatePackageFromJAXB", p3.getDescription());
        assertEquals("checkInComment: update package testUpdatePackageFromJAXB", p3.getCheckInComment());
        //assertEquals("version3", p3.getCheckInComment());
        assertEquals(new URL(generateBaseUrl() + "/packages/testUpdatePackageFromJAXB/source").toExternalForm(), p3.getSourceLink().toString());
        assertEquals(new URL(generateBaseUrl() + "/packages/testUpdatePackageFromJAXB/binary").toExternalForm(), p3.getBinaryLink().toString());
        PackageMetadata pm3 = p3.getMetadata();
        assertFalse(pm3.isArchived());
        assertNotNull(pm3.getCreated());
        assertNotNull(pm3.getUuid());
        assertNotNull(pm3.getLastModified());       
   
View Full Code Here

TOP

Related Classes of org.drools.guvnor.server.jaxrs.jaxb.Package

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.