public void testSerial() { assertTrue(_nbhm.isEmpty()); final String k1 = "k1"; final String k2 = "k2"; assertThat(_nbhm.put(k1, "v1"), nullValue()); assertThat(_nbhm.put(k2, "v2"), nullValue()); // Serialize it out try { FileOutputStream fos = new FileOutputStream("NBHM_test.txt"); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject(_nbhm); out.close(); } catch (IOException ex) { ex.printStackTrace(); } // Read it back try { File f = new File("NBHM_test.txt"); FileInputStream fis = new FileInputStream(f); ObjectInputStream in = new ObjectInputStream(fis); NonBlockingIdentityHashMap nbhm = (NonBlockingIdentityHashMap) in.readObject(); in.close(); assertThat( "serialization works", nbhm.toString(), anyOf(is("{k1=v1, k2=v2}"), is("{k2=v2, k1=v1}"))); if (!f.delete()) throw new IOException("delete failed"); } catch (IOException ex) { ex.printStackTrace(); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } }
/** * POST Test: specify an option. * * @throws IOException I/O exception */ @Test public void postOption() throws IOException { assertEquals( "2", post( "", "<query xmlns=\"" + URI + "\">" + "<text>2, delete node <a/></text>" + "<option name='" + MainOptions.MIXUPDATES.name() + "' value='true'/></query>", APP_XML)); try { post( "", "<query xmlns=\"" + URI + "\">" + "<text>1, delete node <a/></text>" + "<option name='" + MainOptions.MIXUPDATES.name() + "' value='false'/></query>", APP_XML); fail("Error expected."); } catch (final IOException ex) { assertContains(ex.getMessage(), "[XUST0001]"); } }
/* @Test public void searchContentTest() throws IOException { System.out.println("Search"); textbuddy.searchContent("textfile.txt"); }*/ public boolean testIfFilesAreTheSame(File file1, File file2) { BufferedReader file1Reader = null; BufferedReader file2Reader = null; boolean equals = true; ; try { file1Reader = new BufferedReader(new FileReader(file1)); file2Reader = new BufferedReader(new FileReader(file2)); String linefromfile1; String linefromfile2; while (((linefromfile1 = file1Reader.readLine()) != null) && ((linefromfile2 = file2Reader.readLine()) != null)) { if (!linefromfile1.equals(linefromfile2)) { equals = false; break; } } } catch (IOException e) { e.printStackTrace(); } finally { try { file1Reader.close(); file2Reader.close(); } catch (IOException e) { e.printStackTrace(); } } return equals; }
// @Test public void validateDoubfulRanks() { try { BufferedReader bufferedReader = new BufferedReader( new FileReader(new File("/home/alext/Downloads/NCBI/taxdump/nodes.dmp"))); String line; while ((line = bufferedReader.readLine()) != null) { String[] split = line.split("\t\\|\t"); if (split[2].equals("forma")) { System.out.println(line); // break; } } bufferedReader.close(); } catch (FileNotFoundException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (IOException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } }
/** POST Test: execute buggy query. */ @Test public void postErr() { try { assertEquals("", post("", "<query xmlns=\"" + URI + "\"><text>(</text></query>", APP_XML)); } catch (final IOException ex) { assertContains(ex.getMessage(), "[XPST0003]"); } }
public void serve(Socket s) { try { doService(s); synchronized (this) { notify(); } s.close(); } catch (IOException e) { e.printStackTrace(); } }
@Before public void setUp() { try { URL res = this.getClass().getClassLoader().getResource("toolspecs"); // use the file toolspec xml as the input file too (for this test) toolspecsDir = res.getFile(); repo = new LocalToolRepository(res.getFile()); } catch (IOException ex) { fail(ex.getMessage()); } }
private TFile getFile(String extension, String location) { File file = TempFileProvider.createTempFile("moduleManagementToolTest-", extension); InputStream is = this.getClass().getClassLoader().getResourceAsStream(location); assertNotNull(is); OutputStream os; try { os = new FileOutputStream(file); FileCopyUtils.copy(is, os); } catch (IOException error) { error.printStackTrace(); } return new TFile(file); }
@Test public final void testStreams() throws Exception { for (int i = 0; i < 100; i++) { try { runStreamTest(i); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage() + ": " + i); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage() + ": " + i); } } for (int i = 100; i < 2000; i += 250) { try { runStreamTest(i); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage() + ": " + i); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage() + ": " + i); } } for (int i = 2000; i < 80000; i += 1000) { try { runStreamTest(i); } catch (IOException e) { e.printStackTrace(); fail(e.getMessage() + ": " + i); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage() + ": " + i); } } }
@Test public void testCreateCises() { for (int i = 0; i < this.numCIS; i++) { String cisId; String testTitle = "CPA: "; LOG.info("[#" + testCaseNumber + "] " + testTitle); // Create CIS LOG.info("############## CREATED CIS with Id:" + cssId + " (" + cssPassword + ")"); Future<ICisOwned> futureCis = TestCase1096.cisManager.createCis( cisName, cisType, cisMembershipCriteria, cisDescription); ICisOwned newCis = null; assertNotNull("Future new CIS is null", futureCis); // Retrieve future CIS try { newCis = futureCis.get(10, TimeUnit.SECONDS); } catch (InterruptedException e) { LOG.error("[Error " + e.getLocalizedMessage() + "] " + testTitle, e); fail("[Error InterruptedException] " + testTitle); } catch (ExecutionException e) { LOG.error("[Error " + e.getLocalizedMessage() + "] " + testTitle, e); fail("[Error ExecutionException] " + testTitle); } catch (TimeoutException e) { LOG.error("[Error " + e.getLocalizedMessage() + "] " + testTitle, e); fail("[Error TimeoutException] " + testTitle); } assertNotNull("New CIS is null", newCis); // Retrieve CIS id cisId = newCis.getCisId(); cisIds.add(cisId); assertNotNull("New CIS id is null", cisIds); // Check if the CIS is on the CIS Management registry ICis cisRetrieved = TestCase1096.cisManager.getCis(cisId); assertNotNull("New CIS is not stored", cisRetrieved); assertEquals("New CIS and retrived CIS should be the same but are not", newCis, cisRetrieved); } LOG.info("Starting simulation and injection of fake activities.."); ArrayList<String[]> data = new ArrayList<String[]>(); try { URL u = NominalTestCase.class.getClassLoader().getResource("msn-data-xml.csv"); BufferedReader br = new BufferedReader(new InputStreamReader(u.openStream())); CSVParser parser = new CSVParser(br, CSVStrategy.EXCEL_STRATEGY); String[] value = parser.getLine(); while (value != null) { data.add(value); value = parser.getLine(); } } catch (FileNotFoundException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } catch (IOException e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. } long msgCounter = 0; for (String[] line : data) { msgCounter++; TestCase1096.cisManager .getCis(cisIds.get(0)) .getActivityFeed() .addActivity(makeMessage(line[1], line[2], "nonsense", "0"), this); if (msgCounter > 2000) { break; } } LOG.info("cisIds.size(): " + cisIds.size()); assert (cisIds.size() == this.numCIS); }