Example #1
0
  @Test
  public void issue_43() {

    String json = "{\"test\":null}";

    Assertions.assertThat(read(json, "test")).isNull();

    Assertions.assertThat(
            JsonPath.using(
                    Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS))
                .parse(json)
                .read("nonExistingProperty"))
        .isNull();

    try {
      read(json, "nonExistingProperty");

      failBecauseExceptionWasNotThrown(PathNotFoundException.class);
    } catch (PathNotFoundException e) {

    }

    try {
      read(json, "nonExisting.property");

      failBecauseExceptionWasNotThrown(PathNotFoundException.class);
    } catch (PathNotFoundException e) {
    }
  }
  @Test
  @DecisionResource(resource = RESULT_TEST_DMN)
  public void testMultipleResults() {
    DmnDecisionTableResult decisionResult =
        evaluateWithMatchingRules(NO_OUTPUT_VALUE, SINGLE_OUTPUT_VALUE, MULTIPLE_OUTPUT_VALUES);
    assertThat(decisionResult).hasSize(3);

    DmnDecisionRuleResult ruleResult = decisionResult.get(0);
    assertNoOutputValue(ruleResult);
    ruleResult = decisionResult.get(1);
    assertSingleOutputValue(ruleResult);
    ruleResult = decisionResult.get(2);
    assertMultipleOutputValues(ruleResult);

    ruleResult = decisionResult.getFirstResult();
    assertNoOutputValue(ruleResult);

    try {
      decisionResult.getSingleResult();
      failBecauseExceptionWasNotThrown(DmnDecisionResultException.class);
    } catch (DmnDecisionResultException e) {
      assertThat(e)
          .hasMessageStartingWith("DMN-01008")
          .hasMessageContaining("singleValue")
          .hasMessageContaining("multipleValues1")
          .hasMessageContaining("multipleValues2");
    }
  }
  @Test
  public void verifyBehaviorInCaseOfExceptionWithoutTransactionBlocking() {
    final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
    final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);

    //noinspection unchecked
    final PutResolver<ContentValues> putResolver = mock(PutResolver.class);

    final List<ContentValues> contentValues = singletonList(mock(ContentValues.class));

    when(putResolver.performPut(same(storIOSQLite), any(ContentValues.class)))
        .thenThrow(new IllegalStateException("test exception"));

    try {
      new PreparedPutContentValuesIterable.Builder(storIOSQLite, contentValues)
          .withPutResolver(putResolver)
          .useTransaction(false)
          .prepare()
          .executeAsBlocking();

      failBecauseExceptionWasNotThrown(StorIOException.class);
    } catch (StorIOException expected) {
      IllegalStateException cause = (IllegalStateException) expected.getCause();
      assertThat(cause).hasMessage("test exception");

      // Main check of this test
      verify(internal, never()).endTransaction();

      verify(storIOSQLite).internal();
      verify(putResolver).performPut(same(storIOSQLite), any(ContentValues.class));
      verifyNoMoreInteractions(storIOSQLite, internal, putResolver);
    }
  }
    @Test
    public void shouldFinishTransactionIfExceptionHasOccurredBlocking() {
      final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
      final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);

      when(storIOSQLite.internal()).thenReturn(internal);

      //noinspection unchecked
      final DeleteResolver<Object> deleteResolver = mock(DeleteResolver.class);

      when(deleteResolver.performDelete(same(storIOSQLite), anyObject()))
          .thenThrow(new IllegalStateException("test exception"));

      try {
        new PreparedDeleteCollectionOfObjects.Builder<Object>(
                storIOSQLite, singletonList(new Object()))
            .useTransaction(true)
            .withDeleteResolver(deleteResolver)
            .prepare()
            .executeAsBlocking();

        failBecauseExceptionWasNotThrown(StorIOException.class);
      } catch (StorIOException expected) {
        IllegalStateException cause = (IllegalStateException) expected.getCause();
        assertThat(cause).hasMessage("test exception");

        verify(internal).beginTransaction();
        verify(internal, never()).setTransactionSuccessful();
        verify(internal).endTransaction();

        verify(storIOSQLite).internal();
        verify(deleteResolver).performDelete(same(storIOSQLite), anyObject());
        verifyNoMoreInteractions(storIOSQLite, internal, deleteResolver);
      }
    }
    @Test
    public void
        shouldThrowExceptionIfNoTypeMappingWasFoundWithTransactionWithoutAffectingDbBlocking() {
      final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
      final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);

      when(storIOSQLite.lowLevel()).thenReturn(internal);

      when(storIOSQLite.put()).thenReturn(new PreparedPut.Builder(storIOSQLite));

      final List<TestItem> items = asList(TestItem.newInstance(), TestItem.newInstance());

      final PreparedPut<PutResults<TestItem>> preparedPut =
          storIOSQLite.put().objects(items).useTransaction(true).prepare();

      try {
        preparedPut.executeAsBlocking();
        failBecauseExceptionWasNotThrown(StorIOException.class);
      } catch (StorIOException expected) {
        // it's okay, no type mapping was found
        assertThat(expected).hasCauseInstanceOf(IllegalStateException.class);
      }

      verify(storIOSQLite).put();
      verify(storIOSQLite).lowLevel();
      verify(internal).typeMapping(TestItem.class);
      verify(internal, never()).insert(any(InsertQuery.class), any(ContentValues.class));
      verify(internal, never()).update(any(UpdateQuery.class), any(ContentValues.class));
      verifyNoMoreInteractions(storIOSQLite, internal);
    }
 @Test
 public void testNullManager() throws Exception {
   try {
     new RiakClusterManager(null);
     failBecauseExceptionWasNotThrown(NullPointerException.class);
   } catch (NullPointerException e) {
   }
 }
 @Test
 public void should_fail_if_on_of_the_iterable_element_does_not_have_given_property_or_field() {
   try {
     assertThat(employees).filteredOn("secret", notIn("???"));
     failBecauseExceptionWasNotThrown(IntrospectionError.class);
   } catch (IntrospectionError e) {
     assertThat(e).hasMessageContaining("Can't find any field or property with name 'secret'");
   }
 }
Example #8
0
 @Test
 public void checkNotEmptyExceptionMessage() {
   try {
     checkNotEmpty(null, "expected message");
     failBecauseExceptionWasNotThrown(NullPointerException.class);
   } catch (NullPointerException e) {
     assertThat(e).hasMessage("expected message");
   }
 }
Example #9
0
 @Test
 public void checkNotEmptyEmptyExceptionMessage() {
   try {
     checkNotEmpty("", "expected message");
     failBecauseExceptionWasNotThrown(IllegalStateException.class);
   } catch (IllegalStateException e) {
     assertThat(e).hasMessage("expected message");
   }
 }
 @Test
 public void resourceWithDenyAllAndNoAuth401() {
   try {
     target("/test/denied").request().get(String.class);
     failBecauseExceptionWasNotThrown(WebApplicationException.class);
   } catch (WebApplicationException e) {
     assertThat(e.getResponse().getStatus()).isEqualTo(401);
   }
 }
 @Test
 public void should_fail_if_actual_is_instance_of_type() {
   AssertionInfo info = someInfo();
   try {
     objects.assertIsNotInstanceOf(info, actual, Person.class);
     failBecauseExceptionWasNotThrown(AssertionError.class);
   } catch (AssertionError err) {
   }
   verify(failures).failure(info, shouldNotBeInstance(actual, Person.class));
 }
Example #12
0
 @Test
 public void shouldReturnCorrectObject() {
   final Object obj = new Object();
   try {
     Match(obj).of(Case($(0), 0));
     failBecauseExceptionWasNotThrown(MatchError.class);
   } catch (MatchError matchError) {
     assertThat(matchError.getObject()).isEqualTo(obj);
   }
 }
 @Test
 public void resourceWithAuthenticationWithoutAuthorizationNoCredentials401() {
   try {
     target("/test/profile").request().get(String.class);
     failBecauseExceptionWasNotThrown(WebApplicationException.class);
   } catch (WebApplicationException e) {
     assertThat(e.getResponse().getStatus()).isEqualTo(401);
     assertThat(e.getResponse().getHeaders().get(HttpHeaders.WWW_AUTHENTICATE))
         .containsOnly(getPrefix() + " realm=\"realm\"");
   }
 }
 @Test
 public void respondsToMissingCredentialsWith401() throws Exception {
   try {
     target("/test/admin").request().get(String.class);
     failBecauseExceptionWasNotThrown(WebApplicationException.class);
   } catch (WebApplicationException e) {
     assertThat(e.getResponse().getStatus()).isEqualTo(401);
     assertThat(e.getResponse().getHeaders().get(HttpHeaders.WWW_AUTHENTICATE))
         .containsOnly(getPrefix() + " realm=\"realm\"");
   }
 }
Example #15
0
 @Test
 public void testSemanticError() throws QuarkException, SQLException {
   SqlQueryParser parser = new SqlQueryParser(info);
   try {
     parser.parse(
         "select count(*) from test.many_colum where "
             + "test.many_columns.j > 100 and test.many_columns.i = 10");
     failBecauseExceptionWasNotThrown(SQLException.class);
   } catch (SQLException e) {
     assertThat((Throwable) e).hasMessageContaining("Table 'TEST.MANY_COLUM' not found");
   }
 }
Example #16
0
 @Test
 public void testSyntaxError() throws QuarkException, SQLException {
   SqlQueryParser parser = new SqlQueryParser(info);
   try {
     parser.parse(
         "select count(*) test.many_columns where "
             + "test.many_columns.j > 100 and test.many_columns.i = 10");
     failBecauseExceptionWasNotThrown(SQLException.class);
   } catch (SQLException e) {
     assertThat((Throwable) e).hasMessageContaining("Encountered \".\" at line 1, column 21.");
   }
 }
 @Test
 public void should_fail_if_filter_is_on_private_field_and_reading_private_field_is_disabled() {
   setAllowExtractingPrivateFields(false);
   try {
     assertThat(employees).filteredOn("city", notIn("New York")).isEmpty();
     failBecauseExceptionWasNotThrown(IntrospectionError.class);
   } catch (IntrospectionError e) {
     // expected
   } finally {
     setAllowExtractingPrivateFields(true);
   }
 }
 @Test
 public void resourceWithDenyAllAndAuth403() {
   try {
     target("/test/denied")
         .request()
         .header(HttpHeaders.AUTHORIZATION, getPrefix() + " " + getGoodGuyValidToken())
         .get(String.class);
     failBecauseExceptionWasNotThrown(WebApplicationException.class);
   } catch (WebApplicationException e) {
     assertThat(e.getResponse().getStatus()).isEqualTo(403);
   }
 }
 @Test
 public void respondsToExceptionsWith500() throws Exception {
   try {
     target("/test/admin")
         .request()
         .header(HttpHeaders.AUTHORIZATION, getPrefix() + " " + getBadGuyToken())
         .get(String.class);
     failBecauseExceptionWasNotThrown(WebApplicationException.class);
   } catch (WebApplicationException e) {
     assertThat(e.getResponse().getStatus()).isEqualTo(500);
   }
 }
 @Test
 public void resourceWithAuthorizationPrincipalIsNotAuthorized403() {
   try {
     target("/test/admin")
         .request()
         .header(HttpHeaders.AUTHORIZATION, getPrefix() + " " + getOrdinaryGuyValidToken())
         .get(String.class);
     failBecauseExceptionWasNotThrown(WebApplicationException.class);
   } catch (WebApplicationException e) {
     assertThat(e.getResponse().getStatus()).isEqualTo(403);
   }
 }
 @Test
 public void testDeleteInNotManagedRealm() throws Exception {
   try {
     getRestTemplate()
         .exchange(
             delete(URI.create(getRawSyncBaseUri() + "/clients/animals/1"))
                 .header(AUTHORIZATION, USER1_ACCESS_TOKEN)
                 .build(),
             Void.class);
     failBecauseExceptionWasNotThrown(HttpClientErrorException.class);
   } catch (HttpClientErrorException e) {
     assertThat(e.getStatusCode()).isEqualTo(BAD_REQUEST);
   }
 }
 @Test
 public void testDeleteServicesClientNotFound() throws Exception {
   try {
     getRestTemplate()
         .exchange(
             delete(URI.create(getRawSyncBaseUri() + "/clients/services/not-found"))
                 .header(AUTHORIZATION, USER1_ACCESS_TOKEN)
                 .build(),
             Void.class);
     failBecauseExceptionWasNotThrown(HttpClientErrorException.class);
   } catch (final HttpClientErrorException e) {
     assertThat(e.getStatusCode()).isEqualTo(NOT_FOUND);
   }
 }
 @Test
 public void testDeleteUnauthorized() throws Exception {
   try {
     getRestTemplate()
         .exchange(
             delete(URI.create(getRawSyncBaseUri() + "/clients/animals/1"))
                 .header(AUTHORIZATION, INVALID_ACCESS_TOKEN)
                 .build(),
             Void.class);
     failBecauseExceptionWasNotThrown(HttpClientErrorException.class);
   } catch (HttpClientErrorException e) {
     assertThat(e.getStatusCode()).isEqualTo(UNAUTHORIZED);
   }
 }
 @Test
 public void testDeleteForbidden() throws Exception {
   try {
     getRestTemplate()
         .exchange(
             delete(URI.create(getRawSyncBaseUri() + "/clients/animals/1"))
                 .header(AUTHORIZATION, INSUFFICIENT_SCOPES_ACCESS_TOKEN)
                 .build(),
             Void.class);
     failBecauseExceptionWasNotThrown(HttpClientErrorException.class);
   } catch (HttpClientErrorException e) {
     assertThat(e.getStatusCode()).isEqualTo(FORBIDDEN);
   }
 }
 @Test
 public void testDeleteTokeninfoServerError() throws Exception {
   try {
     getRestTemplate()
         .exchange(
             delete(URI.create(getRawSyncBaseUri() + "/clients/animals/1"))
                 .header(AUTHORIZATION, SERVER_ERROR_ACCESS_TOKEN)
                 .build(),
             Void.class);
     failBecauseExceptionWasNotThrown(HttpServerErrorException.class);
   } catch (HttpServerErrorException e) {
     assertThat(e.getStatusCode()).isEqualTo(INTERNAL_SERVER_ERROR);
   }
 }
 @Test
 public void testUpdateServicesClientNotFound() throws Exception {
   try {
     final URI uri = URI.create(getRawSyncBaseUri() + "/clients/services/not-found");
     getRestTemplate()
         .exchange(
             patch(uri)
                 .contentType(APPLICATION_JSON)
                 .header(AUTHORIZATION, USER1_ACCESS_TOKEN)
                 .body(new Client()),
             Void.class);
     failBecauseExceptionWasNotThrown(HttpClientErrorException.class);
   } catch (final HttpClientErrorException e) {
     assertThat(e.getStatusCode()).isEqualTo(NOT_FOUND);
   }
 }
Example #27
0
  @Test
  public void issue_46() {

    String json = "{\"a\": {}}";

    Configuration configuration =
        Configuration.defaultConfiguration().setOptions(Option.SUPPRESS_EXCEPTIONS);
    Assertions.assertThat(JsonPath.using(configuration).parse(json).read("a.x")).isNull();

    try {
      read(json, "a.x");

      failBecauseExceptionWasNotThrown(PathNotFoundException.class);
    } catch (PathNotFoundException e) {
      Assertions.assertThat(e).hasMessage("No results for path: $['a']['x']");
    }
  }
  @Override
  @Test
  public void simpleCreateShouldWork() throws RepositoryException, URISyntaxException, IOException {
    final Node node = createBasicNode();

    // try to inject some data to create a new version... already not possible to create a node with
    // a versions object :)
    final JSONNode version;
    try {
      version = (JSONNode) accessor.convertFrom("{\"properties\" : {}}");
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    try {
      getAccessor().perform(node, "foo", API.CREATE_OR_UPDATE, version, context);
      failBecauseExceptionWasNotThrown(UnsupportedOperationException.class);
    } catch (UnsupportedOperationException e) {
      assertThat(e.getLocalizedMessage()).contains("create", "update");
    }
  }
    @Test
    public void verifyBehaviorInCaseOfExceptionWithoutTransactionBlocking() {
      final StorIOSQLite storIOSQLite = mock(StorIOSQLite.class);
      final StorIOSQLite.Internal internal = mock(StorIOSQLite.Internal.class);

      when(storIOSQLite.lowLevel()).thenReturn(internal);

      //noinspection unchecked
      final PutResolver<Object> putResolver = mock(PutResolver.class);

      when(putResolver.performPut(same(storIOSQLite), anyObject()))
          .thenThrow(new IllegalStateException("test exception"));

      final List<Object> objects = singletonList(new Object());

      try {
        new PreparedPutCollectionOfObjects.Builder<Object>(storIOSQLite, objects)
            .useTransaction(false)
            .withPutResolver(putResolver)
            .prepare()
            .executeAsBlocking();

        failBecauseExceptionWasNotThrown(StorIOException.class);
      } catch (StorIOException expected) {
        IllegalStateException cause = (IllegalStateException) expected.getCause();
        assertThat(cause).hasMessage("test exception");

        // Main checks of this test
        verify(internal, never()).beginTransaction();
        verify(internal, never()).setTransactionSuccessful();
        verify(internal, never()).endTransaction();

        verify(storIOSQLite).lowLevel();
        verify(putResolver).performPut(same(storIOSQLite), anyObject());
        verifyNoMoreInteractions(storIOSQLite, internal, putResolver);
      }
    }
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void testHttpsWithEmptyCertFile() {
   Connectors.https(mock(Server.class), 1010, "", "ewerk");
   failBecauseExceptionWasNotThrown(IllegalArgumentException.class);
 }