Package ch.inftec.ju.util

Examples of ch.inftec.ju.util.IOUtil


          if (JuUtils.getJuPropertyChain().get("ju-testing.export.compareToResource", Boolean.class, true)) {
            // Perform export in-memory and compare to resource
            String resourcePrefix = this.dataSetConfigInfo.getResourcePrefix();
            String resourcePath = resourcePrefix + "/" + targetFileName;
            URL resourceUrl = JuUrl.singleResource(resourcePath);
            String resourceString = new IOUtil().loadTextFromUrl(resourceUrl);
           
            String xmlString = xmlOutput.getXmlString();
           
            logger.debug("Comparing DB export to resource {}", resourceUrl);
            Assert.assertEquals(resourceString, xmlString);
View Full Code Here


         * @return Unmarshalled object
         * @throws ServiceDbException If the unmarshalling fails
         * @param <T> Type of expected object
         */
        public <T> T unmarshal(URL xmlUrl, Class<T> objClass) {
          String xmlString = new IOUtil().loadTextFromUrl(xmlUrl);
         
            @SuppressWarnings("unchecked")
            T object = (T)this.unmarshalRaw(xmlString, objClass);
           
            return object;
View Full Code Here

    TestUtils.assertEqualsResource("XmlUtilsTest_canCreateXml_fromJaxbObject_usingFormattedOutput.xml", xmlString);
  }
 
  @Test
  public void canCreate_object_fromXml() throws Exception {
    String xmlString = new IOUtil().loadTextFromUrl(JuUrl.resourceRelativeTo("XmlUtilsTest_canCreateXml_fromJaxbObject.xml", XmlUtilsJaxbTest.class));
    Object o = XmlUtils.marshaller().unmarshalRaw(xmlString, Player.class);
    this.assertMichael((Player) o);
  }
View Full Code Here

    this.assertMichael((Player) o);
  }
 
  @Test
  public void canCreate_typedOject_fromXml() throws Exception {
    String xmlString = new IOUtil().loadTextFromUrl(JuUrl.resourceRelativeTo("XmlUtilsTest_canCreateXml_fromJaxbObject.xml", XmlUtilsJaxbTest.class));
    Player p = XmlUtils.marshaller().unmarshal(xmlString, Player.class);
    this.assertMichael(p);
  }
View Full Code Here

  @Test
  public void canNot_createObject_fromXml_withoutNamespace() throws Exception {
    exception.expect(JuRuntimeException.class);
    exception.expectCause(Is.isA(UnmarshalException.class));
   
    String xmlString = new IOUtil().loadTextFromUrl(JuUrl.resourceRelativeTo("XmlUtilsTest_michael_noNamespace.xml", XmlUtilsJaxbTest.class));
    Object o = XmlUtils.marshaller().unmarshalRaw(xmlString, Player.class);
    this.assertMichael((Player) o);
  }
View Full Code Here

      .marshalToString(this.getMichael(100));
  }
 
  @Test
  public void canUnmarshal_invalidXml_whenNotUsingSchema() throws Exception {
    String xmlString = new IOUtil().loadTextFromUrl(JuUrl.resourceRelativeTo("XmlUtilsTest_michael_invalid.xml", this.getClass()));
    XmlUtils.marshaller().unmarshal(xmlString, Player.class);
  }
View Full Code Here

  @Test
  public void canNotUnmarshal_invalidXml_whenUsingSchema() throws Exception {
    exception.expect(JuRuntimeException.class);
    exception.expectCause(Is.isA(UnmarshalException.class));
   
    String xmlString = new IOUtil().loadTextFromUrl(JuUrl.resourceRelativeTo("XmlUtilsTest_michael_invalid.xml", this.getClass()));
   
    XmlUtils.marshaller()
      .schema(JuUrl.resourceRelativeTo("player.xsd", this.getClass()))
      .unmarshal(xmlString, Player.class);
  }
View Full Code Here

         * @return Unmarshalled object
         * @throws ServiceDbException If the unmarshalling fails
         * @param <T> Type of expected object
         */
        public <T> T unmarshal(URL xmlUrl, Class<T> objClass) {
          String xmlString = new IOUtil().loadTextFromUrl(xmlUrl);
         
            @SuppressWarnings("unchecked")
            T object = (T)this.unmarshalRaw(xmlString, objClass);
           
            return object;
View Full Code Here

      this.excludedFilterObjectProperties.add("class");
    }
   
    public NativeQueryBuilder fromResourceRelativeTo(Class<?> clazz, String resourceName) {
      URL url = JuUrl.existingResourceRelativeTo(resourceName, clazz);
      this.baseQuery = new IOUtil().loadTextFromUrl(url);
     
      return this;
    }
View Full Code Here

   * This will marshall the object to a JSON string, format both and then compare them as Strings.
   * @param resourceName Name of the resource that has to be in the same package as the calling class
   * @param Object obj to be conpared to the JSON resource
   */
  public static void assertEqualsJsonResource(String resourceName, Object obj) {
    String resJson = new IOUtil("UTF-8").loadTextFromUrl(
        JuUrl.resource().exceptionIfNone().relativeTo(ReflectUtils.getCallingClass()).get(resourceName));
   
    String objJson = JsonUtils.marshaller().formattedOutput(true).marshalToString(obj);
    Assert.assertEquals(JsonUtils.formatJson(resJson), objJson);
  }
View Full Code Here

TOP

Related Classes of ch.inftec.ju.util.IOUtil

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.