@Test public void testTagPoolParser () throws BuenOjoCSVParserException { TagPoolCSVParser parser = new TagPoolCSVParser(new ByteArrayResource(csvString.getBytes(StandardCharsets.UTF_8))); Course course = new Course(); course.setId(new Long(1000)); try { List<Tag> tags = parser.parse(course); assertThat(tags).isNotNull().isNotEmpty(); assertThat(tags.size()).isNotZero().isEqualTo(7); assertThat(tags.get(0).getNumber()).isEqualTo(1); assertThat(tags.get(1).getNumber()).isEqualTo(2); List<TagPool> tagPool = parser.parseTagPool(); assertThat(tagPool).isNotNull().isNotEmpty(); assertThat(tagPool.size()).isNotZero().isEqualTo(11); } catch (IOException e) { Fail.fail(e.getMessage()); } }
@Test public void queryMapKeysMustBeStrings() throws Exception { server.enqueue(new MockResponse()); TestInterface api = new TestInterfaceBuilder().target("http://localhost:" + server.getPort()); Map<Object, String> queryMap = new LinkedHashMap<Object, String>(); queryMap.put(Integer.valueOf(42), "alice"); try { api.queryMap((Map) queryMap); Fail.failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException ex) { assertThat(ex).hasMessage("QueryMap key must be a String: 42"); } }
private void loadConfiguration() { Properties sysProps = System.getProperties(); String configFileName = sysProps.getProperty("test.config.filename"); if (StringUtils.isEmpty(configFileName)) { configFileName = defaultConfigurationFileName; } try { AllConfiguration = new DefaultConfigurationBuilder(configFileName).getConfiguration(); ((HierarchicalConfiguration) AllConfiguration).setExpressionEngine(new XPathExpressionEngine()); } catch (Exception e) { Fail.fail("failed to read config file", e); log.error("Failed to read config file", e); } }
/** * Checks if the file opened correctly * * @param states * the different states of the region */ public void checkIfFileOpened(String... states) { Region match = null; try { // check if file opened SikuliXAutomation.setSearchRegion(SCREEN); match = findMultipleStateRegion(DEFAULT_TIMEOUT, states); // close editor match.click(); closeFocusedProgram(); } catch (FindFailed e) { Fail.fail("File did not open.", e); } }
/** * Checks if the file did not open. * * @param states * the different states of the region */ public void checkIfFileNotOpened(String... states) { Region match = null; try { // check if file opened SikuliXAutomation.setSearchRegion(SCREEN); match = findMultipleStateRegion(DEFAULT_TIMEOUT, states); // close editor match.click(); closeFocusedProgram(); Fail.fail("File did open."); } catch (FindFailed e) { } }
protected void assertMultipleOutputValues(DmnDecisionResultEntries result) { assertThat(result.size()).isEqualTo(2); String value = (String) result.get("firstOutput"); assertThat(value).isEqualTo("multipleValues1"); value = (String) result.get("secondOutput"); assertThat(value).isEqualTo("multipleValues2"); value = result.getFirstEntry(); assertThat(value).isEqualTo("multipleValues1"); try { result.getSingleEntry(); Fail.failBecauseExceptionWasNotThrown(DmnDecisionResultException.class); } catch (DmnDecisionResultException e) { assertThat(e) .hasMessageStartingWith("DMN-01010") .hasMessageContaining("multipleValues1") .hasMessageContaining("multipleValues2"); } }
protected void assertMultipleOutputValues(DmnDecisionRuleResult decisionRuleResult) { assertThat(decisionRuleResult.size()).isEqualTo(2); String value = (String) decisionRuleResult.get("firstOutput"); assertThat(value).isEqualTo("multipleValues1"); value = (String) decisionRuleResult.get("secondOutput"); assertThat(value).isEqualTo("multipleValues2"); value = decisionRuleResult.getFirstEntry(); assertThat(value).isEqualTo("multipleValues1"); try { decisionRuleResult.getSingleEntry(); Fail.failBecauseExceptionWasNotThrown(DmnDecisionResultException.class); } catch (DmnDecisionResultException e) { assertThat(e) .hasMessageStartingWith("DMN-01007") .hasMessageContaining("multipleValues1") .hasMessageContaining("multipleValues2"); } }
@Test public void testAwsV4SignatureBadIdentity() throws Exception { client = AmazonS3ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider( new BasicAWSCredentials( "bad-access-key", awsCreds.getAWSSecretKey()))) .withEndpointConfiguration(s3EndpointConfig) .build(); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(BYTE_SOURCE.size()); try { client.putObject(containerName, "foo", BYTE_SOURCE.openStream(), metadata); Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class); } catch (AmazonS3Exception e) { assertThat(e.getErrorCode()).isEqualTo("InvalidAccessKeyId"); } }
@Test public void testAwsV4SignatureBadCredential() throws Exception { client = AmazonS3ClientBuilder.standard() .withCredentials(new AWSStaticCredentialsProvider( new BasicAWSCredentials( awsCreds.getAWSAccessKeyId(), "bad-secret-key"))) .withEndpointConfiguration(s3EndpointConfig) .build(); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(BYTE_SOURCE.size()); try { client.putObject(containerName, "foo", BYTE_SOURCE.openStream(), metadata); Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class); } catch (AmazonS3Exception e) { assertThat(e.getErrorCode()).isEqualTo("SignatureDoesNotMatch"); } }
@Test public void testUpdateBlobXmlAcls() throws Exception { assumeTrue(!Quirks.NO_BLOB_ACCESS_CONTROL.contains(blobStoreType)); String blobName = "testUpdateBlobXmlAcls-blob"; ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(BYTE_SOURCE.size()); client.putObject(containerName, blobName, BYTE_SOURCE.openStream(), metadata); AccessControlList acl = client.getObjectAcl(containerName, blobName); acl.grantPermission(GroupGrantee.AllUsers, Permission.Read); client.setObjectAcl(containerName, blobName, acl); assertThat(client.getObjectAcl(containerName, blobName)).isEqualTo(acl); acl.revokeAllPermissions(GroupGrantee.AllUsers); client.setObjectAcl(containerName, blobName, acl); assertThat(client.getObjectAcl(containerName, blobName)).isEqualTo(acl); acl.grantPermission(GroupGrantee.AllUsers, Permission.Write); try { client.setObjectAcl(containerName, blobName, acl); Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class); } catch (AmazonS3Exception e) { assertThat(e.getErrorCode()).isEqualTo("NotImplemented"); } }
@Test public void testPartNumberMarker() throws Exception { String blobName = "foo"; InitiateMultipartUploadResult result = client.initiateMultipartUpload( new InitiateMultipartUploadRequest(containerName, blobName)); ListPartsRequest request = new ListPartsRequest(containerName, blobName, result.getUploadId()); client.listParts(request.withPartNumberMarker(0)); try { client.listParts(request.withPartNumberMarker(1)); Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class); } catch (AmazonS3Exception e) { assertThat(e.getErrorCode()).isEqualTo("NotImplemented"); } }
@Test public void testBlobRemove() throws Exception { String blobName = "blob"; ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(BYTE_SOURCE.size()); client.putObject(containerName, blobName, BYTE_SOURCE.openStream(), metadata); assertThat(client.getObjectMetadata(containerName, blobName)) .isNotNull(); client.deleteObject(containerName, blobName); try { client.getObjectMetadata(containerName, blobName); Fail.failBecauseExceptionWasNotThrown(AmazonS3Exception.class); } catch (AmazonS3Exception e) { assertThat(e.getErrorCode()).isEqualTo("404 Not Found"); } client.deleteObject(containerName, blobName); }
@Test public void test() { TestCase innerTestCAse = Mockito.mock(TestCase.class); when(innerTestCAse.getSparqlWhere()).thenReturn(sparqlQuery); TestCase testCaseWithTarget = TestCaseWithTarget.builder() .testCase(innerTestCAse) .target(target) .filterSpqrql(" ?this <http://example.cpm/p> ?value .") .build(); String finalSparql = PrefixNSService.getSparqlPrefixDecl() + testCaseWithTarget.getSparqlWhere(); assertThat(finalSparql) .contains(target.getPattern()); try { QueryFactory.create(finalSparql); } catch (Exception e) { Fail.fail("Failed sparql query:\n" + finalSparql, e); } }
@Test public void testTagCircleParse() { InputStream in = new ByteArrayInputStream(csvString.getBytes(StandardCharsets.UTF_8)); TagCircleCSVParser parser = new TagCircleCSVParser(in); List<TagCircle> list = null; try { list = parser.parse(); } catch (Exception e) { assertThat(e).isInstanceOf(IOException.class); Fail.fail(e.getMessage()); } assertThat(list).isNotEmpty(); assertThat(list).isNotNull(); assertThat(list.size()).isEqualTo(2); assertThat(list.get(0).getNumber()).isEqualTo(0); assertThat(list.get(0).getX()).isEqualTo(431); assertThat(list.get(0).getY()).isEqualTo(197); assertThat(list.get(0).getRadioPx()).isCloseTo(73.72f, Offset.offset(0.1f)); assertThat(list.get(1).getNumber()).isEqualTo(1); assertThat(list.get(1).getX()).isEqualTo(344); assertThat(list.get(1).getY()).isEqualTo(317); assertThat(list.get(1).getRadioPx()).isCloseTo(29.49f, Offset.offset(0.1f)); }
public SELF_TYPE thenThrowNoException() { if (exceptionThrownOptional.isPresent()) { Exception e = exceptionThrownOptional.get(); // TODO [bilu] 06.11.17 more detailed stack Fail.fail("Expected no exception, found exception of class " + e.getClass() + " with message " + e.getMessage() + ". Caused by " + e.getCause()); } return self(); }
@Test public void onlyOneQueryMapAnnotationPermitted() throws Exception { try { parseAndValidateMetadata(QueryMapTestInterface.class, "multipleQueryMap", Map.class, Map.class); Fail.failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException ex) { assertThat(ex).hasMessage("QueryMap annotation was present on multiple parameters."); } }
@Test public void queryMapMustBeInstanceOfMap() throws Exception { try { parseAndValidateMetadata(QueryMapTestInterface.class, "nonMapQueryMap", String.class); Fail.failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException ex) { assertThat(ex).hasMessage("QueryMap parameter must be a Map: class java.lang.String"); } }
@Test public void onlyOneHeaderMapAnnotationPermitted() throws Exception { try { parseAndValidateMetadata(HeaderMapInterface.class, "multipleHeaderMap", Map.class, Map.class); Fail.failBecauseExceptionWasNotThrown(IllegalStateException.class); } catch (IllegalStateException ex) { assertThat(ex).hasMessage("HeaderMap annotation was present on multiple parameters."); } }
@Test public void shouldNotWrapRuntimeException() throws Exception { final RuntimeException someException = new RuntimeException(); ExceptionThrower<Exception> et = new ExceptionThrower<Exception>(someException); try { callUglyCode(et); Fail.failBecauseExceptionWasNotThrown(RuntimeException.class); } catch (RuntimeException e) { assertThat(e).isSameAs(someException); } }
@Test public void shouldNotWrapRuntimeException_guava() throws Exception { final RuntimeException someException = new RuntimeException(); ExceptionThrower<Exception> et = new ExceptionThrower<Exception>(someException); try { callUglyCode_guava(et); Fail.failBecauseExceptionWasNotThrown(RuntimeException.class); } catch (RuntimeException e) { assertThat(e).isSameAs(someException); } }
public void testDeleteNonExisting() { final SimpleTestEntity ent = new SimpleTestEntity(); ent.setId(Long.MAX_VALUE); try { dao.delete(ent); Fail.fail("Exception should have been thrown!"); } catch (final Throwable t) { final boolean causedBy = Throwables.isCausedByType(t, EmptyResultDataAccessException.class); if (!causedBy) { throw Err.process(t); } } }
@Transactional public void testWriteAndRead() { final SimpleTestEntity ent1 = new SimpleTestEntity(); ent1.setName("one"); Assertions.assertThat(dao.isEmpty()).isTrue(); dao.save(ent1); Assertions.assertThat(dao.isEmpty()).isFalse(); ent1.setName("two"); dao.save(ent1); final SimpleTestEntity ent2 = new SimpleTestEntity(); ent2.setName("999"); dao.save(ent2); List<SimpleTestEntity> all = dao.findAll(); Assertions.assertThat(all.size()).isEqualTo(2); for (final SimpleTestEntity e : all) { if (e.getId().equals(ent1.getId())) { Assertions.assertThat(e.getName()).isEqualTo(ent1.getName()); } else if (e.getId().equals(ent2.getId())) { Assertions.assertThat(e.getName()).isEqualTo(ent2.getName()); } else { Fail.fail("Unbekannte Entity: " + e.getId()); } } final SimpleTestEntity example = new SimpleTestEntity(); example.setName("two"); all = dao.findAll(example); Assertions.assertThat(all.size()).isEqualTo(1); Assertions.assertThat(all.get(0).getName()).isEqualTo("two"); }
public void testBeanValidation() { try { final SimpleTestEntity entWithoutName = new SimpleTestEntity(); dao.save(entWithoutName); Fail.fail("Exception expected"); } catch (final Throwable t) { final ConstraintViolationException e = Throwables.getCauseByType(t, ConstraintViolationException.class); Assertions.assertThat(e).isNotNull(); Err.process(e); } }
public void testDeleteNonExisting() { final TestEntity ent = new TestEntity(); ent.setId(Long.MAX_VALUE); try { dao.delete(ent); Fail.fail("Exception should have been thrown!"); } catch (final Throwable t) { final boolean causedBy = Throwables.isCausedByType(t, EmptyResultDataAccessException.class); if (!causedBy) { throw Err.process(t); } } }
@Transactional public void testWriteAndRead() { final TestEntity ent1 = new TestEntity(); ent1.setName("one"); Assertions.assertThat(dao.isEmpty()).isTrue(); dao.save(ent1); Assertions.assertThat(dao.isEmpty()).isFalse(); Assertions.assertThat(ent1.getCreated()).isNotNull(); Assertions.assertThat(ent1.getUpdated()).isNotNull(); ent1.setName("two"); dao.save(ent1); final TestEntity ent2 = new TestEntity(); ent2.setName("999"); dao.save(ent2); List<TestEntity> all = dao.findAll(); Assertions.assertThat(all.size()).isEqualTo(2); for (final TestEntity e : all) { if (e.getId().equals(ent1.getId())) { Assertions.assertThat(e.getName()).isEqualTo(ent1.getName()); } else if (e.getId().equals(ent2.getId())) { Assertions.assertThat(e.getName()).isEqualTo(ent2.getName()); } else { Fail.fail("Unbekannte Entity: " + e.getId()); } } final TestEntity example = new TestEntity(); example.setName("two"); all = dao.findAll(example); Assertions.assertThat(all.size()).isEqualTo(1); Assertions.assertThat(all.get(0).getName()).isEqualTo("two"); }
public void testBeanValidation() { try { final TestEntity entWithoutName = new TestEntity(); dao.save(entWithoutName); Fail.fail("Exception expected"); } catch (final Throwable t) { final ConstraintViolationException e = Throwables.getCauseByType(t, ConstraintViolationException.class); Assertions.assertThat(e).isNotNull(); Err.process(e); } }
public void testDeleteNonExisting() { final SimpleTestEntity ent = new SimpleTestEntity(); ent.setId(Long.MAX_VALUE); ent.setName("asdf"); try { dao.delete(ent); Fail.fail("Exception should have been thrown!"); } catch (final Throwable t) { final boolean causedBy = Throwables.isCausedByType(t, EmptyResultDataAccessException.class); if (!causedBy) { throw Err.process(t); } } }
public void testBeanValidation() { try { final SimpleTestEntity entWithoutName = new SimpleTestEntity(); dao.save(entWithoutName); Fail.fail("Exception expected"); } catch (final Throwable t) { final ValidationException e = Throwables.getCauseByType(t, ValidationException.class); Assertions.assertThat(e).as(Throwables.getFullStackTrace(t)).isNotNull(); Err.process(e); } }
public void testMultiplePersistenceUnitsWorkWithNestedRollback() { final long countBeforeTestDao = testDao.count(); final long countBeforeAnotherTestDao = anotherTestDao.count(); final long countBeforeAnotherPuTestDao = anotherPuTestDao.count(); try { testMultiplePersistenceUnitsWorkWithRollback(); Fail.fail("exception should have been thrown"); } catch (final RuntimeException e) { Assertions.assertThat(e.getMessage()).contains("rollback reason"); } Assertions.assertThat(testDao.count()).isEqualTo(countBeforeTestDao); Assertions.assertThat(anotherTestDao.count()).isEqualTo(countBeforeAnotherTestDao); Assertions.assertThat(anotherPuTestDao.count()).isEqualTo(countBeforeAnotherPuTestDao); }
/** * Checks if the program opened * * @param states * the different states of the region */ public void checkIfProgramOpened(String... states) { try { // check if file opened SikuliXAutomation.setSearchRegion(SCREEN); findMultipleStateRegion(DEFAULT_TIMEOUT, states); } catch (FindFailed e) { Fail.fail("Program did not open.", e); } }