Package org.rhq.test

Examples of org.rhq.test.ObjectCollectionSerializer


            InputStream dataStream = getClass().getResourceAsStream(inventoryFile);

            Reader rdr = new TokenReplacingReader(new InputStreamReader(dataStream), replacements);

            @SuppressWarnings("unchecked")
            List<Resource> inventory = (List<Resource>) new ObjectCollectionSerializer().deserialize(rdr);

            //fix up the parent relationships, because they might not be reconstructed correctly by
            //JAXB - we're missing XmlID and XmlIDRef annotations in our model
            fixupParent(null, inventory);
View Full Code Here


        return Arrays.asList(m1, m2);
    }

    private byte[] getSerializedTestObjectTree() throws IOException, JAXBException {
        ObjectCollectionSerializer serializer = new ObjectCollectionSerializer();

        serializer.addObjects(getTestObjectTree());

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        serializer.serialize(out);

        return out.toByteArray();
    }
View Full Code Here

        assert out.length > 0 : "The serialization should have produced some output";
    }

    @Test
    public void testCanDeserialize() throws Exception {
        ObjectCollectionSerializer serializer = new ObjectCollectionSerializer();

        ByteArrayInputStream in = new ByteArrayInputStream(getSerializedTestObjectTree());

        List<?> objects = serializer.deserialize(in);

        assert objects != null && objects.equals(getTestObjectTree()) : "The deserialized objects don't match the expected results";
    }
View Full Code Here

        if (jars.size() > 0) {
            URL[] jarUrls = getUrls(jars);
            classLoaderToUse = new ChildFirstClassLoader(jarUrls, Main.class.getClassLoader());
        }

        ObjectCollectionSerializer serializer = new ObjectCollectionSerializer();

        EntityManager em = null;
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        try {
            Thread.currentThread().setContextClassLoader(classLoaderToUse);
            em = getEntityManager(driverClass, dialect, connectionUrl, username, password, persistenceUnit);
           
            em.getTransaction().begin();
           
            for (String query : queries) {
                log.info("Executing query: " + query);

                Query q = em.createQuery(query);

                @SuppressWarnings("unchecked")
                List<Object> results = q.getResultList();

                for(Object result : results) {
                    HibernateDetachUtility.nullOutUninitializedFields(result, HibernateDetachUtility.SerializationType.SERIALIZATION);
                }
               
                serializer.addObjects(results);
            }
                       
            em.close();           
        } finally {
            Thread.currentThread().setContextClassLoader(contextClassLoader);
        }

        serializer.serialize(System.out);       
    }
View Full Code Here

TOP

Related Classes of org.rhq.test.ObjectCollectionSerializer

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.