Java Code Examples for org.springframework.test.annotation.DirtiesContext.ClassMode#BEFORE_EACH_TEST_METHOD

The following examples show how to use org.springframework.test.annotation.DirtiesContext.ClassMode#BEFORE_EACH_TEST_METHOD . 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: CreateMultipleExecutionsIT.java    From difido-reports with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void testCreateSeparateExecutions() throws Exception {
	for (int i = 0; i < NUM_OF_EXECUTIONS; i++) {
		ExecutionDetails description = new ExecutionDetails();
		description.setShared(false);
		executionId = client.addExecution(description);
		final MachineNode machine = new MachineNode(MACHINE_NAME);
		final int machineId = client.addMachine(executionId, machine);
		final ScenarioNode scenario = new ScenarioNode(SCENARIO_NAME);
		machine.addChild(scenario);
		final TestNode test = new TestNode(0, TEST_NAME, "0");
		uid = String.valueOf(Math.abs(new Random().nextInt()));
		test.setUid(uid);
		scenario.addChild(test);
		client.updateMachine(executionId, machineId, machine);
		client.endExecution(executionId);
	}
	waitForTasksToFinish();
	final Execution[] executions = getAllExecutions();
	Assert.assertNotNull(executions);
	Assert.assertEquals(NUM_OF_EXECUTIONS, executions.length);
}
 
Example 2
Source File: CreateElementsIT.java    From difido-reports with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void testAddReportElement() throws Exception {
	ReportElement element = new ReportElement(details);
	element.setType(ElementType.regular);
	element.setTime("00:00");
	final String title = "My report element";
	element.setTitle(title);
	final String message = "My report element message";
	element.setMessage(message);
	details.addReportElement(element);
	client.addTestDetails(executionId, details);

	waitForTasksToFinish();
	final TestDetails testDetails = assertExecution();
	element = testDetails.getReportElements().get(0);
	Assert.assertEquals(ElementType.regular, element.getType());
	Assert.assertEquals(title, element.getTitle());
	Assert.assertEquals(message, element.getMessage());

}
 
Example 3
Source File: CreateElementsIT.java    From difido-reports with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void measureAddReportElements() throws Exception {
	ReportElement element = null;
	for (int i = 0; i < NUM_OF_REPORTS_ELEMENTS; i++) {
		element = new ReportElement(details);
		element.setType(ElementType.regular);
		element.setTime("00:" + i);
		element.setTitle("My report element " + i);
		details.addReportElement(element);
		long start = System.currentTimeMillis();
		client.addTestDetails(executionId, details);
		System.out.println("Element was added in " + (System.currentTimeMillis() - start) + " millis");
	}
	waitForTasksToFinish();
	assertExecution();
	System.out.println("End");

}
 
Example 4
Source File: CreateElementsIT.java    From difido-reports with Apache License 2.0 6 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void testAddFile() throws Exception {
	final File file = new File("src/test/resources/top-q.pdf");
	ReportElement element = new ReportElement(details);
	element.setType(ElementType.lnk);
	element.setTime("00:00");
	element.setTitle("My report element");
	element.setMessage(file.getName());
	details.addReportElement(element);
	client.addTestDetails(executionId, details);
	client.addFileFromClasspath(executionId, uid, file);
	waitForTasksToFinish();
	assertExecution();

}
 
Example 5
Source File: CreateMultipleExecutionsIT.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void testCreateSharedExecutions() throws Exception {
	ExecutionDetails description = new ExecutionDetails();
	description.setShared(true);
	executionId = client.addExecution(description);
	for (int i = 0; i < NUM_OF_EXECUTIONS; i++) {
		final MachineNode machine = new MachineNode(MACHINE_NAME + " " + i);
		final int machineId = client.addMachine(executionId, machine);
		final ScenarioNode scenario = new ScenarioNode(SCENARIO_NAME);
		machine.addChild(scenario);
		final TestNode test = new TestNode(0, TEST_NAME, "0");
		uid = String.valueOf(Math.abs(new Random().nextInt()));
		test.setUid(uid);
		scenario.addChild(test);
		client.updateMachine(executionId, machineId, machine);
	}
	client.endExecution(executionId);
	waitForTasksToFinish();
	final Execution[] executions = getAllExecutions();
	Assert.assertNotNull(executions);
	Assert.assertEquals(1, executions.length);
	Assert.assertNotNull(executions[0].getMachines());
	Assert.assertEquals(NUM_OF_EXECUTIONS, executions[0].getMachines().size());
	for (int i = 0 ; i < NUM_OF_EXECUTIONS ; i++) {
		Assert.assertEquals(MACHINE_NAME + " " + i, executions[0].getMachines().get(i).getName());
	}
}
 
Example 6
Source File: ConcurrencyExecutionIT.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void testConcurrentSharedExecutions() throws Exception {
	Thread[] threads = new Thread[NUM_OF_THREADS];
	long start = System.currentTimeMillis();
	for (int i = 0; i < NUM_OF_THREADS; i++) {
		threads[i] = new ExecutionRunThread(true, NUM_OF_TESTS_IN_SCENARIO);
		threads[i].start();
		// We need to give it a bit time to update the data. If not, we may
		// fail sometime because the server will not find a shared
		// execution.
		Thread.sleep(400);
	}
	for (int i = 0; i < NUM_OF_THREADS; i++) {
		threads[i].join();
	}

	System.out.println("Finished all reports in " + (System.currentTimeMillis() - start) + " millis");
	start = System.currentTimeMillis();

	final Execution execution = getExecution();
	Assert.assertNotNull(execution);
	Assert.assertEquals("Not all machines were joined to a single execution", NUM_OF_THREADS,
			execution.getMachines().size());
	for (int i = 0; i < NUM_OF_THREADS; i++) {
		final MachineNode machine = execution.getMachines().get(0);
		final String threadName = machine.getName();
		Assert.assertEquals(1, machine.getChildren().size());
		final ScenarioNode scenario = machine.getChildren().get(0);
		Assert.assertTrue(scenario.getName().contains(threadName));
		Assert.assertEquals(NUM_OF_TESTS_IN_SCENARIO, scenario.getChildren().size());
		for (int j = 0; j < NUM_OF_TESTS_IN_SCENARIO; j++) {
			final String testName = scenario.getChildren().get(j).getName();
			Assert.assertTrue(testName.contains(threadName));
		}

	}
	System.out.println("Finished assertions in " + (System.currentTimeMillis() - start) + " millis");

}
 
Example 7
Source File: ConcurrencyExecutionIT.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void testConcurrentSeparateExecutions() throws Exception {
	Thread[] threads = new Thread[NUM_OF_THREADS];
	long start = System.currentTimeMillis();
	for (int i = 0; i < NUM_OF_THREADS; i++) {
		threads[i] = new ExecutionRunThread(false, NUM_OF_TESTS_IN_SCENARIO);
		threads[i].start();
	}
	for (int i = 0; i < NUM_OF_THREADS; i++) {
		threads[i].join();
	}

	System.out.println("Finished all reports in " + (System.currentTimeMillis() - start) + " millis");

	waitForTasksToFinish();
	start = System.currentTimeMillis();
	Assert.assertEquals(NUM_OF_THREADS, metadataRepository.count());
	final Execution[] executions = getAllExecutions();
	Assert.assertNotNull(executions);
	Assert.assertEquals(NUM_OF_THREADS, executions.length);
	for (int i = 0; i < executions.length; i++) {
		Assert.assertEquals(1, executions[i].getMachines().size());
		final MachineNode machine = executions[i].getMachines().get(0);
		final String threadName = machine.getName();
		Assert.assertEquals(1, machine.getChildren().size());
		final ScenarioNode scenario = machine.getChildren().get(0);
		Assert.assertTrue(scenario.getName().contains(threadName));
		Assert.assertEquals("Number of tests in the scenario is not as expected", NUM_OF_TESTS_IN_SCENARIO,
				scenario.getChildren().size());
		for (int j = 0; j < NUM_OF_TESTS_IN_SCENARIO; j++) {
			final String testName = scenario.getChildren().get(j).getName();
			Assert.assertTrue(testName.contains(threadName));
		}

	}
	System.out.println("Finished assertions in " + (System.currentTimeMillis() - start) + " millis");

}
 
Example 8
Source File: TestDeactiveExecutionIT.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void testCreateAndDestroyExecution() throws Exception {
	final String executionUid = String.valueOf(System.currentTimeMillis() / 10000)
			+ String.valueOf(new Random().nextInt(100));
	final int executionId = client.addExecution(new ExecutionDetails("Testing", true));
	final MachineNode machine = new MachineNode("Machine");
	final int machineId = client.addMachine(executionId, machine);
	Assert.assertNotEquals("Recieved wrong maching id ", -1, machineId);
	final ScenarioNode scenario = new ScenarioNode("Scenario ");
	machine.addChild(scenario);
	for (int i = 0; i < NUM_OF_TESTS_IN_SCENARIO; i++) {
		final String uid = executionUid + "-" + i;
		final TestNode test = new TestNode(i, "Test " , uid);
		scenario.addChild(test);
		client.updateMachine(executionId, machineId, machine);
		TestDetails details = new TestDetails(uid);
		ReportElement element = new ReportElement(details);
		element.setType(ElementType.regular);
		element.setTime("00:" + i);
		element.setTitle("Element from thread #" + i);
		element.setMessage("Element message from thread #" + i);
		details.addReportElement(element);
		client.addTestDetails(executionId, details);
	}
	client.endExecution(executionId);
	//TODO: Assert that execution is no longer active
}
 
Example 9
Source File: FileUploadIT.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void uploadLargeFile() throws Exception {
	String fileName = "test_file.tmp";
	tempFile = new File(System.getProperty("java.io.tmpdir"), fileName);
	writeContentToFile(tempFile, FILE_SIZE_IN_MB);
	long expectedFileSize = tempFile.length();
	client.addFileFromFileSystem(executionId, uid, tempFile);
	waitForTasksToFinish();
	Thread.sleep(500);
	File uploadedFiles[] = findFilesInTest(uid, fileName);
	Assert.assertEquals(1, uploadedFiles.length);
	Assert.assertNotNull(uploadedFiles[0]);
	Assert.assertEquals(expectedFileSize, uploadedFiles[0].length());
}
 
Example 10
Source File: ExecutionResourceIT.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void testPut() throws Exception {
	ExecutionDetails executionDetails = new ExecutionDetails();
	int executionId = client.addExecution(executionDetails);
	client.endExecution(executionId);
	
}
 
Example 11
Source File: ReportResourceIT.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void testGetReports() throws Exception {
	ExecutionDetails execution = new ExecutionDetails();
	execution.setShared(false);
	client.addExecution(execution);
	DataTable table = getExecutionMetaData();
	Assert.assertNotNull(table);
}
 
Example 12
Source File: ExecutionResourceIT.java    From difido-reports with Apache License 2.0 4 votes vote down vote up
@Test
@DirtiesContext(classMode = ClassMode.BEFORE_EACH_TEST_METHOD)
public void getGet() throws Exception {
	client.addExecution(new ExecutionDetails());
	assertThat(metadataRepository.count(), equalTo(1L));
}