@Test public void createCollection() throws IOException { ObjectNode schema = Schemas.json(context.getFullName("schema"), "/item/name", "/item/description"); ObjectNode item = schema.with("definition").with("xml").with("item"); item.with("name").put("_indexed", true); item.with("description").put("_indexed", true); item.with("boolean").put("_indexed", true); schemaId = schemas.getId(schemas.create(schema)); ObjectNode collection = CollectionJson.json(context.getFullName("collection"), schemaId, null); ObjectNode metadataRules = collection.with("security").with("metadata"); metadataRules.put( UUID.randomUUID().toString(), metadataRule(Files.readFile(getClass().getResourceAsStream("script.js")), "DISCOVER_ITEM", "U:" + USER, false)); collectionUuid = collections.getId(collections.create(collection)); }
@Test public void skipiosProjectCompiles() throws Exception { final File dir = new File("target/tests/noicompile/").getAbsoluteFile(); File generated = generateFromArchetype("m-n-test", dir, "-Diospath=target/skip"); File created = new File(generated, "client"); assertTrue(created.isDirectory(), "Project created"); File pom = new File(created, "pom.xml"); assertTrue(pom.isFile(), "Pom file is in there"); assertFalse(Files.readFile(pom).contains("ios"), "There should be no mention of ios in " + pom); Verifier v = createVerifier(created.getParent()); v.getCliOptions().add("-Denforcer.fail=true"); v.executeGoal("package"); v.verifyErrorFreeLog(); File nbactions = new File(created, "nbactions.xml"); assertTrue(nbactions.isFile(), "Actions file is in there"); assertFalse(Files.readFile(nbactions).contains("robovm"), "There should be no mention of robovm in " + nbactions); }
private File findDialogs(File root, StringBuilder sb) throws IOException { if (root.isDirectory()) { File found = null; for (File f : root.listFiles()) { File r = findDialogs(f, sb); if (r != null && found == null) { found = r; } } return found; } else { if (root.getName().equals("PlatformServices.java")) { return root; } if (root.getName().endsWith(".java")) { String text = Files.readFile(root); if (text.contains("PlatformServices")) { sb.append("No PlatformServices shall be used ").append(root).append("\n"); } } return null; } }
@Test public void skipiosProjectCompiles() throws Exception { final File dir = new File("target/tests/noicompile/").getAbsoluteFile(); generateFromArchetype("m-n-test", dir, "-Diospath=target/skip"); File created = new File(new File(dir, "m-n-test"), "client"); assertTrue(created.isDirectory(), "Project created"); File pom = new File(created, "pom.xml"); assertTrue(pom.isFile(), "Pom file is in there"); assertFalse(Files.readFile(pom).contains("ios"), "There should be no mention of ios in " + pom); Verifier v = createVerifier(created.getParent()); v.getCliOptions().add("-Denforcer.fail=true"); v.executeGoal("package"); v.verifyErrorFreeLog(); File nbactions = new File(created, "nbactions.xml"); assertTrue(nbactions.isFile(), "Actions file is in there"); assertFalse(Files.readFile(nbactions).contains("robovm"), "There should be no mention of robovm in " + nbactions); }
@Test(description = "Test check_disk output") public void testCheckDisk() throws IOException { InputStream is = ClassLoader .getSystemResourceAsStream("check_disk.txt"); String message = Files.readFile(is); NagiosCheckResult checkResult = NagiosCheckResult.fromMessage(message); Collection<NagiosPerformanceData> perfDataCollection = checkResult .getPerfData(); assertEquals(perfDataCollection.size(), 1); Iterator<NagiosPerformanceData> it = perfDataCollection.iterator(); // test perfdata for /=2016MB;9832;9822;0;9842 NagiosPerformanceData perfData = it.next(); assertEquals(perfData.getName(), "/"); assertEquals(perfData.getCurrent(), 2016.0); assertEquals(perfData.getWarning(), 9832.0); assertEquals(perfData.getCritical(), 9822.0); assertEquals(perfData.getMinimum(), 0.0); assertEquals(perfData.getMaximum(), 9842.0); }
@Test(description = "Test replacing") public void testReplacing() throws IOException { InputStream is = ClassLoader .getSystemResourceAsStream("output_case3.txt"); String message = Files.readFile(is); NagiosCheckResult checkResult = new NagiosCheckResult(); checkResult.addPerfDataReplacement("_", "."); checkResult.parseMessage(message); assertEquals(checkResult.getPerfData().get(0).getName(), "perfdata.line1"); assertEquals(checkResult.getPerfData().get(1).getName(), "perfdata.line2"); assertEquals(checkResult.getPerfData().get(2).getName(), "perfdata.line3"); assertEquals(checkResult.getPerfData().get(3).getName(), "perfdata.line4"); }
private static void assertNoTextInSubdir(String fx, File genRoot) throws IOException { if (genRoot.isFile()) { if (Files.readFile(genRoot).contains(fx)) { fail("String " + fx + " is in file " + genRoot); } } else { for (File ch : genRoot.listFiles()) { assertNoTextInSubdir(fx, ch); } } }
@Override protected boolean assertPlatformServicesEmpty(File dir) throws IOException { StringBuilder sb = new StringBuilder(); File dialogs = findDialogs(dir, sb); assertNotNull(dialogs, "PlatformServices file found"); String text = Files.readFile(dialogs); assertEquals(text.indexOf("confirmByUser"), -1, "Do method confirmByUser in the file: " + dialogs); assertEquals(text.indexOf("screenSize"), -1, "Do method screenSize in the file: " + dialogs); assertEquals(sb.length(), 0, sb.toString()); return true; }
@Test(groups = { "tempfile" }) public void test_withTempFile_creates_and_deletes_a_file() throws Exception { final File file = TempFile.withTempFile("content\n1", f -> { assertTrue(f.exists()); assertTrue(f.isFile()); assertEquals(Files.readFile(f), "content\n1\n"); return f; }); assertNotNull(file); assertFalse(file.exists()); }
@Test(groups = { "tempfile" }) public void test_withTempFileP_creates_and_deletes_a_file() throws Exception { final File[] file = new File[] { null }; TempFile.withTempFileP("content\n2", f -> { assertTrue(f.exists()); assertTrue(f.isFile()); assertEquals(Files.readFile(f), "content\n2\n"); file[0] = f; }); assertNotNull(file[0]); assertFalse(file[0].exists()); }
@Test(description = "Test check_linux_procstat.pl output") public void testCheckLinuxProcstat() throws IOException { InputStream is = ClassLoader .getSystemResourceAsStream("check_linux_procstat.pl.txt"); String message = Files.readFile(is); NagiosCheckResult checkResult = NagiosCheckResult.fromMessage(message); assertEquals(checkResult.getPerfData().size(), 11); }
@Test(description = "Test check_load output") public void testCheckLoad() throws IOException { InputStream is = ClassLoader .getSystemResourceAsStream("check_load.txt"); String message = Files.readFile(is); NagiosCheckResult checkResult = NagiosCheckResult.fromMessage(message); Collection<NagiosPerformanceData> perfDataCollection = checkResult .getPerfData(); assertEquals(perfDataCollection.size(), 3); Iterator<NagiosPerformanceData> it = perfDataCollection.iterator(); // test perfdata for load1=0.200;4.000;8.000;0; NagiosPerformanceData perfData = it.next(); assertEquals(perfData.getName(), "load1"); assertEquals(perfData.getCurrent(), 0.2); assertEquals(perfData.getWarning(), 4.0); assertEquals(perfData.getCritical(), 8.0); assertEquals(perfData.getMinimum(), 0.0); // test perfdata for load5=0.170;4.000;8.000;0; perfData = it.next(); assertEquals(perfData.getName(), "load5"); assertEquals(perfData.getCurrent(), 0.17); assertEquals(perfData.getWarning(), 4.0); assertEquals(perfData.getCritical(), 8.0); assertEquals(perfData.getMinimum(), 0.0); // test perfdata for load15=0.270;4.000;8.000;0; perfData = it.next(); assertEquals(perfData.getName(), "load15"); assertEquals(perfData.getCurrent(), 0.27); assertEquals(perfData.getWarning(), 4.0); assertEquals(perfData.getCritical(), 8.0); assertEquals(perfData.getMinimum(), 0.0); }
@Test(description = "Test check_cpu_stats.sh output") public void testCheckCpuStats() throws IOException { InputStream is = ClassLoader .getSystemResourceAsStream("check_cpu_stats.sh.txt"); String message = Files.readFile(is); NagiosCheckResult checkResult = NagiosCheckResult.fromMessage(message); Collection<NagiosPerformanceData> perfDataCollection = checkResult .getPerfData(); assertEquals(perfDataCollection.size(), 2); Iterator<NagiosPerformanceData> it = perfDataCollection.iterator(); // test perfdata for CpuSTEAL=0.17;30;100 NagiosPerformanceData perfData = it.next(); assertEquals(perfData.getName(), "CpuSTEAL"); assertEquals(perfData.getCurrent(), 0.17); assertEquals(perfData.getWarning(), 30.0); assertEquals(perfData.getCritical(), 100.0); // test perfdata for CpuIOWAIT=0.00;30;100 perfData = it.next(); assertEquals(perfData.getName(), "CpuIOWAIT"); assertEquals(perfData.getCurrent(), 0.0); assertEquals(perfData.getWarning(), 30.0); assertEquals(perfData.getCritical(), 100.0); }
@Test(description = "Test check_cassandra_cluster.sh output") public void testCheckCassandraCluster() throws IOException { InputStream is = ClassLoader .getSystemResourceAsStream("check_cassandra_cluster.sh.txt"); String message = Files.readFile(is); NagiosCheckResult checkResult = NagiosCheckResult.fromMessage(message); Collection<NagiosPerformanceData> perfDataCollection = checkResult .getPerfData(); assertEquals(perfDataCollection.size(), 18); Iterator<NagiosPerformanceData> it = perfDataCollection.iterator(); // Load_172.17.45.155=20.78GB NagiosPerformanceData perfData = it.next(); assertEquals(perfData.getName(), "Load_172.17.45.155"); assertEquals(perfData.getCurrent(), 20.78); // Tokens_172.17.45.155=256 perfData = it.next(); assertEquals(perfData.getName(), "Tokens_172.17.45.155"); assertEquals(perfData.getCurrent(), 256.0); // Owns_172.17.45.155=15.1% perfData = it.next(); assertEquals(perfData.getName(), "Owns_172.17.45.155"); assertEquals(perfData.getCurrent(), 15.1); // Load_172.17.45.154=18.06GB perfData = it.next(); assertEquals(perfData.getName(), "Load_172.17.45.154"); assertEquals(perfData.getCurrent(), 18.06); // Tokens_172.17.45.154=256 perfData = it.next(); assertEquals(perfData.getName(), "Tokens_172.17.45.154"); assertEquals(perfData.getCurrent(), 256.0); // Owns_172.17.45.154=16.6% perfData = it.next(); assertEquals(perfData.getName(), "Owns_172.17.45.154"); assertEquals(perfData.getCurrent(), 16.6); }
@Test(description = "Test Case1 output") public void testParsingSingleLine() throws IOException { InputStream is = ClassLoader .getSystemResourceAsStream("output_case1.txt"); String message = Files.readFile(is); NagiosCheckResult checkResult = NagiosCheckResult.fromMessage(message); assertEquals(checkResult.getMessage(), "message_line1"); assertEquals(checkResult.getPerfData().size(), 0); }
@Test(description = "Test Case2 output") public void testParsingSingleLineWithPerfdata() throws IOException { InputStream is = ClassLoader .getSystemResourceAsStream("output_case2.txt"); String message = Files.readFile(is); NagiosCheckResult checkResult = NagiosCheckResult.fromMessage(message); assertEquals(checkResult.getMessage(), "message_line1"); assertEquals(checkResult.getPerfData().size(), 1); }
@Test(description = "Test Case3 output") public void testParsingMultipleLinesWithPerfdata() throws IOException { InputStream is = ClassLoader .getSystemResourceAsStream("output_case3.txt"); String message = Files.readFile(is); NagiosCheckResult checkResult = NagiosCheckResult.fromMessage(message); assertEquals(checkResult.getMessage(), "message_line1\nmessage_line2\nmessage_line3\nmessage_line4"); assertEquals(checkResult.getPerfData().size(), 4); }
private void createTokenFile(String fileName, String content) throws IOException { Files.writeFile(content, new File(fileName)); }
@Test(expectedExceptions = MultipleTLVElementException.class) public void testCreateTlvElementFromTooLargeInput_ThrowsMultipleTLVElementException() throws Exception { byte[] tmp = Files.readFile(CommonTestUtil.loadFile("root_content_larger_than_max.tlv")).getBytes(); TLVElement.create(tmp); }
@Test public void defaultProjectCompiles() throws Exception { final File dir = new File("target/tests/fxcompile/").getAbsoluteFile(); File created = generateFromArchetype("o-a-test", dir); assertTrue(created.isDirectory(), "Project created"); assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there"); Verifier v = createVerifier(created.getAbsolutePath()); v.getCliOptions().add("-Denforcer.fail=true"); v.executeGoal("verify"); v.verifyErrorFreeLog(); for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) { if (l.contains("j2js")) { fail("No pre-compilaton:\n" + l); } if (l.contains("-javafx.zip")) { fail("Don't generate the ZIP by default: " + l); } } v = createVerifier(created.getAbsolutePath()); v.addCliOption("-Pdesktop"); v.getCliOptions().add("-Denforcer.fail=true"); v.executeGoals(Arrays.asList("clean", "install")); v.verifyErrorFreeLog(); final String t = "o-a-test-1.0-SNAPSHOT-javafx.zip"; verifyFileInLog(v, t); final File webpages = new File(new File(new File(created, "client"), "target"), getClass().getSimpleName() + "-o-a-test-1.0-SNAPSHOT-webpages.zip"); assertTrue(webpages.exists(), "Web pages file created: " + webpages); JarFile jf = new JarFile(webpages); ZipEntry indexHTML = jf.getEntry("index.html"); assertNotNull(indexHTML, "index.html in ZIP found"); InputStream is = jf.getInputStream(indexHTML); assertHTMLContent(is); assertDialogsEmpty(dir); is.close(); jf.close(); File dataModel = new File(new File(new File(new File(new File(new File(new File(new File(new File( created, "client"), "src"), "main"), "java"), "org"), "someuser"), "test"), "" + oat + ""), "DataModel.java" ); assertTrue(dataModel.isFile(), "Java file exists: " + dataModel); String mainSrc = Files.readFile(dataModel); int bootMethod = mainSrc.indexOf("onPageLoad("); assertNotEquals(bootMethod, -1, "onPageLoad method present: " + mainSrc); int bootMethodEnd = mainSrc.indexOf("}", bootMethod); assertNotEquals(bootMethodEnd, -1, "onPageLoad method present: " + mainSrc); StringBuilder mainSb = new StringBuilder(mainSrc); mainSb.insert(bootMethodEnd, "\n" + "ClassLoader loader = Main.class.getClassLoader();\n" + "if (loader == ClassLoader.getSystemClassLoader()) {\n" + " System.out.println(\"Presenter: \" + org.netbeans.html.boot.spi.Fn.activePresenter().getClass().getName());\n" + " System.exit(0);\n" + "} else {\n" + " throw new IllegalStateException(\"wrong classloader:\" + loader);\n" + "}\n" ); FileWriter w = new FileWriter(dataModel); w.write(mainSb.toString()); w.close(); assertPresenter(created, v, null, "org.netbeans.html.boot.fx.FXPresenter"); assertPresenter(created, v, "-Pwebkit-presenter", "com.dukescript.presenters.webkit.WebKitPresenter"); assertPresenter(created, v, "-Pbrowser-presenter", "com.dukescript.presenters.Browser"); }
@Test public void defaultProjectCompiles() throws Exception { final File dir = new File("target/tests/fxcompile/").getAbsoluteFile(); File created = generateFromArchetype("o-a-test", dir); assertTrue(created.isDirectory(), "Project created"); assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there"); Verifier v = createVerifier(created.getAbsolutePath()); v.getCliOptions().add("-Denforcer.fail=true"); v.executeGoal("verify"); v.verifyErrorFreeLog(); for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) { if (l.contains("j2js")) { fail("No pre-compilaton:\n" + l); } if (l.contains("-javafx.zip")) { fail("Don't generate the ZIP by default: " + l); } } v = createVerifier(created.getAbsolutePath()); v.addCliOption("-Pdesktop"); v.getCliOptions().add("-Denforcer.fail=true"); v.executeGoals(Arrays.asList("clean", "install")); v.verifyErrorFreeLog(); final String t = "o-a-test-1.0-SNAPSHOT-javafx.zip"; verifyFileInLog(v, t); final File webpages = new File(new File(new File(created, "client"), "target"), getClass().getSimpleName() + "-o-a-test-1.0-SNAPSHOT-webpages.zip"); assertTrue(webpages.exists(), "Web pages file created: " + webpages); JarFile jf = new JarFile(webpages); ZipEntry indexHTML = jf.getEntry("index.html"); assertNotNull(indexHTML, "index.html in ZIP found"); InputStream is = jf.getInputStream(indexHTML); assertHTMLContent(is); assertPlatformServicesEmpty(dir); is.close(); jf.close(); File dataModel = new File(new File(new File(new File(new File(new File(new File(new File(new File( created, "client"), "src"), "main"), "java"), "org"), "someuser"), "test"), "" + oat + ""), "DataModel.java" ); assertTrue(dataModel.isFile(), "Java file exists: " + dataModel); String mainSrc = Files.readFile(dataModel); int bootMethod = mainSrc.lastIndexOf("onPageLoad("); assertNotEquals(bootMethod, -1, "onPageLoad method present: " + mainSrc); int bootMethodEnd = mainSrc.indexOf("}", bootMethod); assertNotEquals(bootMethodEnd, -1, "onPageLoad method present: " + mainSrc); StringBuilder mainSb = new StringBuilder(mainSrc); mainSb.insert(bootMethodEnd, "\n" + "ClassLoader loader = Main.class.getClassLoader();\n" + "if (loader == ClassLoader.getSystemClassLoader()) {\n" + " System.out.println(\"Presenter: \" + org.netbeans.html.boot.spi.Fn.activePresenter().getClass().getName());\n" + " System.exit(0);\n" + "} else {\n" + " throw new IllegalStateException(\"wrong classloader:\" + loader);\n" + "}\n" ); FileWriter w = new FileWriter(dataModel); w.write(mainSb.toString()); w.close(); assertPresenter(created, v, null, "org.netbeans.html.boot.fx.FXPresenter"); assertPresenter(created, v, "-Pwebkit-presenter", "com.dukescript.presenters.webkit.WebKitPresenter"); assertPresenter(created, v, "-Pbrowser-presenter", "com.dukescript.presenters.Browser"); }
@Test public void defaultProjectCompiles() throws Exception { final File dir = new File("target/tests/fxcompile/").getAbsoluteFile(); generateFromArchetype("o-a-test", dir); File created = new File(dir, "o-a-test"); assertTrue(created.isDirectory(), "Project created"); assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there"); Verifier v = createVerifier(created.getAbsolutePath()); v.getCliOptions().add("-Denforcer.fail=true"); v.executeGoal("verify"); v.verifyErrorFreeLog(); for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) { if (l.contains("j2js")) { fail("No pre-compilaton:\n" + l); } if (l.contains("-javafx.zip")) { fail("Don't generate the ZIP by default: " + l); } } v = createVerifier(created.getAbsolutePath()); v.getCliOptions().add("-Denforcer.fail=true"); v.addCliOption("-Pdesktop"); v.executeGoals(Arrays.asList("clean", "install")); v.verifyErrorFreeLog(); final String t = "fxcompile/o-a-test/client/target/o-a-test-1.0-SNAPSHOT-javafx.zip"; verifyFileInLog(v, t); File dataModel = new File(new File(new File(new File(new File(new File(new File(new File(new File( created, "client"), "src"), "main"), "java"), "org"), "someuser"), "test"), "" + oat + ""), "UIModel.java" ); assertTrue(dataModel.isFile(), "Java file exists: " + dataModel); String mainSrc = Files.readFile(dataModel); int bootMethod = mainSrc.lastIndexOf("onPageLoad("); assertNotEquals(bootMethod, -1, "onPageLoad method present: " + mainSrc); int bootMethodEnd = mainSrc.indexOf("}", bootMethod); assertNotEquals(bootMethodEnd, -1, "onPageLoad method present: " + mainSrc); StringBuilder mainSb = new StringBuilder(mainSrc); mainSb.insert(bootMethodEnd, "\n" + "ClassLoader loader = Main.class.getClassLoader();\n" + "if (loader == ClassLoader.getSystemClassLoader()) {\n" + " System.out.println(\"Presenter: \" + org.netbeans.html.boot.spi.Fn.activePresenter().getClass().getName());\n" + " System.exit(0);\n" + "} else {\n" + " throw new IllegalStateException(\"wrong classloader:\" + loader);\n" + "}\n" ); FileWriter w = new FileWriter(dataModel); w.write(mainSb.toString()); w.close(); assertPresenter(created, v, null, "org.netbeans.html.boot.fx.FXPresenter"); assertPresenter(created, v, "-Pwebkit-presenter", "com.dukescript.presenters.webkit.WebKitPresenter"); assertPresenter(created, v, "-Pbrowser-presenter", "com.dukescript.presenters.Browser"); }
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(); }
private void oneClickImportTest(String fileToImport) throws URISyntaxException, IOException { URL resourceUrl = getResource(RestControllerV2APIIT.class, fileToImport); File file = new File(new URI(resourceUrl.toString()).getPath()); // Post the file to be imported ValidatableResponse response = given().log() .all() .header(X_MOLGENIS_TOKEN, testUserToken) .multiPart(file) .post(OneClickImporterController.URI + "/upload") .then() .log() .all() .statusCode(OKE); // Verify the post returns a job url String jobUrl = ((ValidatableResponseImpl) response).originalResponse().asString(); assertTrue(jobUrl.startsWith("/api/v2/sys_job_OneClickImportJobExecution/")); String jobStatus = given().log() .all() .header(X_MOLGENIS_TOKEN, testUserToken) .get(jobUrl) .then() .statusCode(OKE) .extract() .path("status"); List<String> validJobStats = Arrays.asList("PENDING", "RUNNING", "SUCCESS"); assertTrue(validJobStats.contains(jobStatus)); await().pollDelay(500, MILLISECONDS) .atMost(3, MINUTES) .until(() -> pollJobForStatus(jobUrl), not(is("PENDING"))); await().pollDelay(500, MILLISECONDS).atMost(10, SECONDS).until(() -> pollJobForStatus(jobUrl), is("SUCCESS")); // Extract the id of the entity created by the import ValidatableResponse completedJobResponse = given().log() .all() .header(X_MOLGENIS_TOKEN, testUserToken) .get(jobUrl) .then() .statusCode(OKE); JsonArray entityTypeId = new Gson().fromJson( completedJobResponse.extract().jsonPath().get("entityTypes").toString(), JsonArray.class); String entityId = entityTypeId.get(0).getAsJsonObject().get("id").getAsString(); String packageName = completedJobResponse.extract().path("package"); String jobId = completedJobResponse.extract().path("identifier"); // Store to use during cleanup importedEntities.add(entityId); importPackages.add(packageName); importJobIds.add(jobId); // Get the entity value to check the import ValidatableResponse entityResponse = given().log() .all() .header(X_MOLGENIS_TOKEN, testUserToken) .get(API_V2 + entityId + "?attrs=~id,first_name,last_name,full_name,UMCG_employee,Age") .then() .log() .all(); entityResponse.statusCode(OKE); JSONAssert.assertEquals(Files.readFile(getClass().getResourceAsStream("users.json")), entityResponse.extract().body().asString(), false); }