org.testng.reporters.Files Java Examples

The following examples show how to use org.testng.reporters.Files. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JwtProxyConfigBuilderTest.java    From che with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void shouldBuildJwtProxyConfigInYamlFormat() throws Exception {
  // given
  Set<String> excludes = new HashSet<>();
  jwtProxyConfigBuilder.addVerifierProxy(
      8080, "http://tomcat:8080", new HashSet<>(excludes), false, "", "/there");
  excludes.add("/api/liveness");
  excludes.add("/other/exclude");
  jwtProxyConfigBuilder.addVerifierProxy(
      4101, "ws://terminal:4101", new HashSet<>(excludes), true, "/cookies", "/here");

  // when
  String jwtProxyConfigYaml = jwtProxyConfigBuilder.build();
  // then
  assertEquals(
      jwtProxyConfigYaml,
      Files.readFile(getClass().getClassLoader().getResourceAsStream("jwtproxy-confg.yaml")));
}
 
Example #2
Source File: AbstractIntegrationTest.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
@Test(enabled = false)
public void generatesCorrectDirectoryStructure() throws IOException {
    DefaultGenerator codeGen = new DefaultGenerator();
    codeGen.setGenerateMetadata(generateMetadata);
    for (Map.Entry<String, String> propertyOverride : globalPropertyOverrides.entrySet()) {
        codeGen.setGeneratorPropertyDefault(propertyOverride.getKey(), propertyOverride.getValue());
    }

    IntegrationTestPathsConfig integrationTestPathsConfig = getIntegrationTestPathsConfig();

    String specContent = Files.readFile(integrationTestPathsConfig.getSpecPath().toFile());
    OpenAPI openAPI = TestUtils.parseContent(specContent);


    CodegenConfig codegenConfig = getCodegenConfig();
    codegenConfig.setOutputDir(integrationTestPathsConfig.getOutputPath().toString());
    codegenConfig.setIgnoreFilePathOverride(integrationTestPathsConfig.getIgnoreFilePath().toFile().toString());
    ClientOptInput opts = new ClientOptInput()
            .config(codegenConfig)
            .openAPI(openAPI);

    codegenConfig.additionalProperties().putAll(configProperties());

    codeGen.opts(opts).generate();

    assertPathEqualsRecursively(integrationTestPathsConfig.getExpectedPath(), integrationTestPathsConfig.getOutputPath());
}
 
Example #3
Source File: OpenAPIV3ParserTest.java    From swagger-parser with Apache License 2.0 5 votes vote down vote up
@Test(description = "A string example should not be over quoted when parsing a yaml node")
public void readingSpecNodeShouldNotOverQuotingStringExample() throws Exception {
    String yaml = Files.readFile(new File("src/test/resources/over-quoted-example.yaml"));
    JsonNode rootNode = Yaml.mapper().readValue(yaml, JsonNode.class);
    OpenAPIV3Parser parser = new OpenAPIV3Parser();
    OpenAPI openAPI = (parser.parseJsonNode(null, rootNode)).getOpenAPI();

    Map<String, Schema> definitions = openAPI.getComponents().getSchemas();
    assertEquals("NoQuotePlease", definitions.get("CustomerType").getExample());
}
 
Example #4
Source File: BundleAndTypeResourcesTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCatalogEntityIconDetails() throws IOException {
    String catalogItemId = "testGetCatalogEntityIconDetails";
    addTestCatalogItemAsEntity(catalogItemId);
    Response response = client().path(URI.create("/catalog/types/" + catalogItemId + "/" + TEST_VERSION + "/icon"))
            .get();
    response.bufferEntity();
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertEquals(response.getMediaType(), MediaType.valueOf("image/png"));
    Image image = Toolkit.getDefaultToolkit().createImage(Files.readFile(response.readEntity(InputStream.class)));
    Assert.assertNotNull(image);
}
 
Example #5
Source File: CatalogResourceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetCatalogEntityIconDetails() throws IOException {
    String catalogItemId = "testGetCatalogEntityIconDetails";
    addTestCatalogItemAsEntity(catalogItemId);
    Response response = client().path(URI.create("/catalog/icon/" + catalogItemId + "/" + TEST_VERSION))
            .get();
    response.bufferEntity();
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertEquals(response.getMediaType(), MediaType.valueOf("image/png"));
    Image image = Toolkit.getDefaultToolkit().createImage(Files.readFile(response.readEntity(InputStream.class)));
    Assert.assertNotNull(image);
}
 
Example #6
Source File: AbstractRestResourceTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public String load(String path) {
    try {
        String base = "http://localhost:"+server.getPort();
        String x = path.startsWith(base) ? path : Urls.mergePaths(base, path);
        log.debug("Reading from: "+x);
        String s = Files.streamToString(new URL(x).openStream());
        log.debug("Result from "+x+": "+s);
        return s;
    } catch (Exception e) {
        throw Exceptions.propagate(e);
    }
}
 
Example #7
Source File: DevfileIntegrityValidatorTest.java    From che with Eclipse Public License 2.0 5 votes vote down vote up
@BeforeClass
public void setUp() throws Exception {
  Map<String, ComponentIntegrityValidator> componentValidators = new HashMap<>();
  componentValidators.put(KUBERNETES_COMPONENT_TYPE, dummyComponentValidator);
  componentValidators.put(OPENSHIFT_COMPONENT_TYPE, dummyComponentValidator);
  componentValidators.put(PLUGIN_COMPONENT_TYPE, dummyComponentValidator);
  componentValidators.put(EDITOR_COMPONENT_TYPE, dummyComponentValidator);

  integrityValidator = new DevfileIntegrityValidator(componentValidators);
  String devFileYamlContent =
      Files.readFile(getClass().getClassLoader().getResourceAsStream("devfile/devfile.yaml"));
  initialDevfile = objectMapper.readValue(devFileYamlContent, DevfileImpl.class);
}
 
Example #8
Source File: JsonConfigLoader.java    From extentreports-java with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void apply() {
    final Gson gson = new GsonBuilder().registerTypeAdapter(instance.getClass(), creator).create();
    try {
        String json = f != null ? Files.readFile(f) : this.json;
        instance = (T) gson.fromJson(json, instance.getClass());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #9
Source File: FHIRCliTest.java    From FHIR with Apache License 2.0 5 votes vote down vote up
private void verifyFileContents(String fname, String... expectedMsgs) throws Exception {
    String fileContents = Files.readFile(new FileInputStream(dirPrefix(fname)));
    for (int i = 0; i < expectedMsgs.length; i++) {
        if (!fileContents.contains(expectedMsgs[i])) {
            fail("File contents didn't contain: '" + expectedMsgs[i] + "'");
        }
    }
}
 
Example #10
Source File: DevfileSchemaValidatorTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private String getResource(String name) throws IOException {
  return Files.readFile(
      getClass().getClassLoader().getResourceAsStream("devfile/schema_test/" + name));
}
 
Example #11
Source File: KubernetesComponentToWorkspaceApplierTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private String getResource(String resourceName) throws IOException {
  return Files.readFile(getClass().getClassLoader().getResourceAsStream(resourceName));
}
 
Example #12
Source File: KubernetesEnvironmentProvisionerTest.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
private String getResource(String resourceName) throws IOException {
  return Files.readFile(getClass().getClassLoader().getResourceAsStream(resourceName));
}
 
Example #13
Source File: CatalogResourceTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test
public void testOsgiBundleWithBom() throws Exception {
    TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
    final String bundleSymbolicName = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FULL;
    final String version = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_VERSION;
    final String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
    final String itemSymbolicName = "my-entity";
    BundleMaker bm = new BundleMaker(manager);
    File f = Os.newTempFile("osgi", "jar");
    Files.copyFile(ResourceUtils.create(this).getResourceFromUrl(bundleUrl), f);
    
    String bom = Joiner.on("\n").join(
            "brooklyn.catalog:",
            "  bundle: " + bundleSymbolicName,
            "  version: " + version,
            "  id: " + itemSymbolicName,
            "  itemType: entity",
            "  name: My Catalog App",
            "  description: My description",
            "  icon_url: classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif",
            "  item:",
            "    type: org.apache.brooklyn.core.test.entity.TestEntity");
    
    f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"), (InputStream) new ByteArrayInputStream(bom.getBytes())));

    Response response = client().path("/catalog")
            .header(HttpHeaders.CONTENT_TYPE, "application/x-jar")
            .post(Streams.readFully(new FileInputStream(f)));

    assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());

    CatalogSummaryAsserts.newInstance(CatalogItemType.ENTITY, itemSymbolicName, version)
            .planYamlPredicate(StringPredicates.containsLiteral("org.apache.brooklyn.core.test.entity.TestEntity"))
            .name("My Catalog App")
            .description("My description")
            .expectedInterfaces(Reflections.getAllInterfaces(TestEntity.class))
            .iconData((data) -> {assertEquals(data.length, 43); return true;})
            .applyAsserts(() -> client());
    
    RegisteredTypeAsserts.newInstance(itemSymbolicName, version)
            .libraryNames(new VersionedName(bundleSymbolicName, version))
            .libraryUrls((String)null)
            .iconUrl("classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif")
            .applyAsserts(getManagementContext().getTypeRegistry());
}
 
Example #14
Source File: CatalogResourceTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test
public void testOsgiBundleWithBomNotInBrooklynNamespace() throws Exception {
    TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH);
    final String bundleSymbolicName = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_SYMBOLIC_NAME_FULL;
    final String version = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_VERSION;
    final String bundleUrl = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_URL;
    final String entityType = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ENTITY;
    final String iconPath = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ICON_PATH;
    final String itemSymbolicName = "my-item";
    BundleMaker bm = new BundleMaker(manager);
    File f = Os.newTempFile("osgi", "jar");
    Files.copyFile(ResourceUtils.create(this).getResourceFromUrl(bundleUrl), f);

    String bom = Joiner.on("\n").join(
            "brooklyn.catalog:",
            "  bundle: " + bundleSymbolicName,
            "  version: " + version,
            "  id: " + itemSymbolicName,
            "  itemType: entity",
            "  name: My Catalog App",
            "  description: My description",
            "  icon_url: classpath:" + iconPath,
            "  item:",
            "    type: " + entityType);

    f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"), (InputStream) new ByteArrayInputStream(bom.getBytes())));

    Response response = client().path("/catalog")
            .header(HttpHeaders.CONTENT_TYPE, "application/x-zip")
            .post(Streams.readFully(new FileInputStream(f)));


    assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());

    CatalogSummaryAsserts.newInstance(CatalogItemType.ENTITY, itemSymbolicName, version)
            .planYamlPredicate(StringPredicates.containsLiteral(entityType))
            .name("My Catalog App")
            .description("My description")
            .expectedInterfaces(ImmutableList.of(Entity.class, BrooklynObject.class, Identifiable.class, Configurable.class))
            .iconData((data) -> {assertEquals(data.length, 43); return true;})
            .applyAsserts(() -> client());
    
    RegisteredTypeAsserts.newInstance(itemSymbolicName, version)
            .libraryNames(new VersionedName(bundleSymbolicName, version))
            .libraryUrls((String)null)
            .iconUrl("classpath:"+iconPath)
            .applyAsserts(getManagementContext().getTypeRegistry());

    // Check that the catalog item is useable (i.e. can deploy the entity)
    String appYaml = Joiner.on("\n").join(
            "services:",
            "- type: " + itemSymbolicName + ":" + version,
            "  name: myEntityName");

    Response appResponse = client().path("/applications")
            .header(HttpHeaders.CONTENT_TYPE, "application/x-yaml")
            .post(appYaml);

    assertEquals(appResponse.getStatus(), Response.Status.CREATED.getStatusCode());

    Entity entity = Iterables.tryFind(getManagementContext().getEntityManager().getEntities(), EntityPredicates.displayNameEqualTo("myEntityName")).get();
    assertEquals(entity.getEntityType().getName(), entityType);
}
 
Example #15
Source File: BundleAndTypeResourcesTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test
public void testOsgiBundleWithBom() throws Exception {
    TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_PATH);
    final String symbolicName = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_SYMBOLIC_NAME_FULL;
    final String version = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_VERSION;
    final String bundleUrl = OsgiStandaloneTest.BROOKLYN_TEST_OSGI_ENTITIES_URL;
    BundleMaker bm = new BundleMaker(manager);
    File f = Os.newTempFile("osgi", "jar");
    Files.copyFile(ResourceUtils.create(this).getResourceFromUrl(bundleUrl), f);
    
    String bom = Joiner.on("\n").join(
            "brooklyn.catalog:",
            "  bundle: " + symbolicName,
            "  version: " + version,
            "  id: " + symbolicName,
            "  itemType: entity",
            "  name: My Catalog App",
            "  description: My description",
            "  icon_url: classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif",
            "  item:",
            "    type: org.apache.brooklyn.core.test.entity.TestEntity");
    
    f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"), (InputStream) new ByteArrayInputStream(bom.getBytes())));

    Response response = client().path("/catalog/bundles")
            .header(HttpHeaders.CONTENT_TYPE, "application/x-jar")
            .post(Streams.readFully(new FileInputStream(f)));
    
    assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());

    TypeDetail entityItem = client().path("/catalog/types/"+symbolicName + "/" + version)
            .get(TypeDetail.class);
    assertEquals(entityItem.getSymbolicName(), symbolicName);
    assertEquals(entityItem.getVersion(), version);

    // assert we can cast it as summary
    TypeSummary entityItemSummary = client().path("/catalog/types/"+symbolicName + "/" + version)
        .get(TypeSummary.class);
    assertEquals(entityItemSummary.getSymbolicName(), symbolicName);
    assertEquals(entityItemSummary.getVersion(), version);

    List<TypeSummary> typesInBundle = client().path("/catalog/bundles/" + symbolicName + "/" + version + "/types")
        .get(new GenericType<List<TypeSummary>>() {});
    assertEquals(Iterables.getOnlyElement(typesInBundle), entityItemSummary);

    TypeDetail entityItemFromBundle = client().path("/catalog/bundles/" + symbolicName + "/" + version + "/types/" + symbolicName + "/" + version)
        .get(TypeDetail.class);
    assertEquals(entityItemFromBundle, entityItem);
    
    // and internally let's check we have libraries
    RegisteredType item = getManagementContext().getTypeRegistry().get(symbolicName, version);
    Assert.assertNotNull(item);
    Collection<OsgiBundleWithUrl> libs = item.getLibraries();
    assertEquals(libs.size(), 1);
    OsgiBundleWithUrl lib = Iterables.getOnlyElement(libs);
    Assert.assertNull(lib.getUrl());

    assertEquals(lib.getSymbolicName(), "org.apache.brooklyn.test.resources.osgi.brooklyn-test-osgi-entities");
    assertEquals(lib.getSuppliedVersionString(), version);

    // now let's check other things on the item
    URI expectedIconUrl = URI.create(getEndpointAddress() + "/catalog/types/" + symbolicName + "/" + entityItem.getVersion()+"/icon").normalize();
    assertEquals(entityItem.getDisplayName(), "My Catalog App");
    assertEquals(entityItem.getDescription(), "My description");
    assertEquals(entityItem.getIconUrl(), expectedIconUrl.getPath());
    assertEquals(item.getIconUrl(), "classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif");

    if (checkTraits(false)) {
        // an InterfacesTag should be created for every catalog item
        @SuppressWarnings("unchecked")
        Map<String, List<String>> traitsMapTag = Iterables.getOnlyElement(Iterables.filter(entityItem.getTags(), Map.class));
        List<String> actualInterfaces = traitsMapTag.get("traits");
        List<Class<?>> expectedInterfaces = Reflections.getAllInterfaces(TestEntity.class);
        assertEquals(actualInterfaces.size(), expectedInterfaces.size());
        for (Class<?> expectedInterface : expectedInterfaces) {
            assertTrue(actualInterfaces.contains(expectedInterface.getName()));
        }
    }

    byte[] iconData = client().path("/catalog/types/" + symbolicName + "/" + version + "/icon").get(byte[].class);
    assertEquals(iconData.length, 43);
}
 
Example #16
Source File: BundleAndTypeResourcesTest.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
@Test
public void testOsgiBundleWithBomNotInBrooklynNamespace() throws Exception {
    TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_PATH);
    final String symbolicName = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_SYMBOLIC_NAME_FULL;
    final String version = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_VERSION;
    final String bundleUrl = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_URL;
    final String entityType = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ENTITY;
    final String iconPath = OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_COM_EXAMPLE_ICON_PATH;
    BundleMaker bm = new BundleMaker(manager);
    File f = Os.newTempFile("osgi", "jar");
    Files.copyFile(ResourceUtils.create(this).getResourceFromUrl(bundleUrl), f);

    String bom = Joiner.on("\n").join(
            "brooklyn.catalog:",
            "  bundle: " + symbolicName,
            "  version: " + version,
            "  id: " + symbolicName,
            "  itemType: entity",
            "  name: My Catalog App",
            "  description: My description",
            "  icon_url: classpath:" + iconPath,
            "  item:",
            "    type: " + entityType);

    f = bm.copyAdding(f, MutableMap.of(new ZipEntry("catalog.bom"), (InputStream) new ByteArrayInputStream(bom.getBytes())));

    Response response = client().path("/catalog/bundles")
            .header(HttpHeaders.CONTENT_TYPE, "application/x-zip")
            .post(Streams.readFully(new FileInputStream(f)));


    assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode());

    TypeDetail entityItem = client().path("/catalog/types/"+symbolicName + "/" + version)
            .get(TypeDetail.class);

    Assert.assertNotNull(entityItem.getPlan().getData());
    Assert.assertTrue(entityItem.getPlan().getData().toString().contains(entityType));

    assertEquals(entityItem.getSymbolicName(), symbolicName);
    assertEquals(entityItem.getVersion(), version);

    // and internally let's check we have libraries
    RegisteredType item = getManagementContext().getTypeRegistry().get(symbolicName, version);
    Assert.assertNotNull(item);
    Collection<OsgiBundleWithUrl> libs = item.getLibraries();
    assertEquals(libs.size(), 1);
    OsgiBundleWithUrl lib = Iterables.getOnlyElement(libs);
    Assert.assertNull(lib.getUrl());

    assertEquals(lib.getSymbolicName(), symbolicName);
    assertEquals(lib.getSuppliedVersionString(), version);

    // now let's check other things on the item
    assertEquals(entityItem.getDescription(), "My description");
    URI expectedIconUrl = URI.create(getEndpointAddress() + "/catalog/types/" + symbolicName + "/" + entityItem.getVersion() + "/icon").normalize();
    assertEquals(entityItem.getIconUrl(), expectedIconUrl.getPath());
    assertEquals(item.getIconUrl(), "classpath:" + iconPath);

    if (checkTraits(false)) {
        // an InterfacesTag should be created for every catalog item
        @SuppressWarnings("unchecked")
        Map<String, List<String>> traitsMapTag = Iterables.getOnlyElement(Iterables.filter(entityItem.getTags(), Map.class));
        List<String> actualInterfaces = traitsMapTag.get("traits");
        List<String> expectedInterfaces = ImmutableList.of(Entity.class.getName(), BrooklynObject.class.getName(), Identifiable.class.getName(), Configurable.class.getName());
        assertTrue(actualInterfaces.containsAll(expectedInterfaces), "actual="+actualInterfaces);
    }

    byte[] iconData = client().path("/catalog/types/" + symbolicName + "/" + version + "/icon").get(byte[].class);
    assertEquals(iconData.length, 43);

    // Check that the catalog item is useable (i.e. can deploy the entity)
    String appYaml = Joiner.on("\n").join(
            "services:",
            "- type: " + symbolicName + ":" + version,
            "  name: myEntityName");

    Response appResponse = client().path("/applications")
            .header(HttpHeaders.CONTENT_TYPE, "application/x-yaml")
            .post(appYaml);

    assertEquals(appResponse.getStatus(), Response.Status.CREATED.getStatusCode());

    Entity entity = Iterables.tryFind(getManagementContext().getEntityManager().getEntities(), EntityPredicates.displayNameEqualTo("myEntityName")).get();
    assertEquals(entity.getEntityType().getName(), entityType);
}
 
Example #17
Source File: ThenHtml5App.java    From JGiven with Apache License 2.0 4 votes vote down vote up
public SELF the_content_of_the_attachment_referenced_by_icon_$_is( int iconNr, String content ) throws IOException, URISyntaxException {
    String href = attachmentIcons.get( iconNr - 1 ).findElement( By.xpath( "../.." ) ).getAttribute( "href" );
    String foundContent = Files.readFile( new File( new URL( href ).toURI() ) ).trim();
    assertThat( content ).isEqualTo( foundContent );
    return self();
}