Ejemplo n.º 1
0
  @Test
  public void deleteLogsByProcessName() {
    KieSession kieSession = createKSession(HELLO_WORLD_PROCESS);

    startProcess(kieSession, HELLO_WORLD_PROCESS_ID, 2);

    // Check that all records are created.
    List<ProcessInstanceLog> resultList =
        auditService
            .processInstanceLogQuery()
            .processId(HELLO_WORLD_PROCESS_ID)
            .processVersion("1.0")
            .build()
            .getResultList();
    Assertions.assertThat(resultList).hasSize(2);
    Assertions.assertThat(resultList)
        .extracting("processName")
        .containsExactly(HELLO_WORLD_P1NAME, HELLO_WORLD_P1NAME);

    // Perform delete
    int resultCount =
        auditService.processInstanceLogDelete().processName(HELLO_WORLD_P1NAME).build().execute();
    Assertions.assertThat(resultCount).isEqualTo(2);

    // Check that all records are gone
    resultList =
        auditService
            .processInstanceLogQuery()
            .processId(HELLO_WORLD_PROCESS_ID)
            .processVersion("1.0")
            .build()
            .getResultList();
    Assertions.assertThat(resultList).hasSize(0);
  }
Ejemplo n.º 2
0
  @Test
  public void issue_33() {
    String json =
        "{ \"store\": {\n"
            + "    \"book\": [ \n"
            + "      { \"category\": \"reference\",\n"
            + "        \"author\": {\n"
            + "          \"name\": \"Author Name\",\n"
            + "          \"age\": 36\n"
            + "        },\n"
            + "        \"title\": \"Sayings of the Century\",\n"
            + "        \"price\": 8.95\n"
            + "      },\n"
            + "      { \"category\": \"fiction\",\n"
            + "        \"author\": \"Evelyn Waugh\",\n"
            + "        \"title\": \"Sword of Honour\",\n"
            + "        \"price\": 12.99,\n"
            + "        \"isbn\": \"0-553-21311-3\"\n"
            + "      }\n"
            + "    ],\n"
            + "    \"bicycle\": {\n"
            + "      \"color\": \"red\",\n"
            + "      \"price\": 19.95\n"
            + "    }\n"
            + "  }\n"
            + "}";

    List<Map<String, Object>> result = read(json, "$.store.book[?(@.author.age == 36)]");

    Assertions.assertThat(result).hasSize(1);
    Assertions.assertThat(result.get(0)).containsEntry("title", "Sayings of the Century");
  }
  /** This method tests the {@code isOfType} assertion method. */
  @Test
  @NeedReload
  public void test_is_of_type() {
    Changes changes = new Changes(source).setStartPointNow();
    update("update test set var14 = 1 where var1 = 1");
    update(
        "insert into test(var1, var2, var11, var10, var9, var3, var12, var8) values(5, true, FILE_READ('classpath:h2-logo-2.png'), '2014-05-24 09:46:30', '2014-05-24', 3, 'test', '09:46:30')");
    changes.setEndPointNow();
    Table table = new Table(source, "test");
    Table table2 = new Table(source, "test2");

    ChangeColumnAssert changeColumnAssert1 = assertThat(changes).change().column("var2");
    ChangeColumnAssert changeColumnAssertReturn1 =
        changeColumnAssert1.isOfType(ValueType.BOOLEAN, true);
    Assertions.assertThat(changeColumnAssert1).isSameAs(changeColumnAssertReturn1);
    ChangeColumnAssert changeColumnAssert2 = assertThat(changes).change(1).column("var2");
    ChangeColumnAssert changeColumnAssertReturn2 =
        changeColumnAssert2.isOfType(ValueType.BOOLEAN, false);
    Assertions.assertThat(changeColumnAssert2).isSameAs(changeColumnAssertReturn2);
    TableColumnAssert tableColumnAssert1 = assertThat(table).column("var2");
    TableColumnAssert tableColumnAssertReturn1 =
        tableColumnAssert1.isOfType(ValueType.BOOLEAN, false);
    Assertions.assertThat(tableColumnAssert1).isSameAs(tableColumnAssertReturn1);
    TableColumnAssert tableColumnAssert2 = assertThat(table2).column("var2");
    TableColumnAssert tableColumnAssertReturn2 =
        tableColumnAssert2.isOfType(ValueType.BOOLEAN, true);
    Assertions.assertThat(tableColumnAssert2).isSameAs(tableColumnAssertReturn2);
  }
Ejemplo n.º 4
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) {
    }
  }
  /** This method should fail because the value is not null. */
  @Test
  @NeedReload
  public void should_fail_because_value_is_not_null() {
    Table table = new Table(source, "test");
    Changes changes = new Changes(table).setStartPointNow();
    update("update test set var14 = 1 where var1 = 1");
    changes.setEndPointNow();

    try {
      assertThat(changes).change().column("var3").valueAtEndPoint().isNull();
      fail("An exception must be raised");
    } catch (AssertionError e) {
      Assertions.assertThat(e.getMessage())
          .isEqualTo(
              String.format(
                  "[Value at end point of Column at index 2 (column name : VAR3) of Change at index 0 (with primary key : [1]) of Changes on TEST table of 'sa/jdbc:h2:mem:test' source] expected:<null> but was:<2>"));
    }
    try {
      assertThat(table).column("var3").value().isNull();
      fail("An exception must be raised");
    } catch (AssertionError e) {
      Assertions.assertThat(e.getMessage())
          .isEqualTo(
              String.format(
                  "[Value at index 0 of Column at index 2 (column name : VAR3) of TEST table] expected:<null> but was:<2>"));
    }
  }
  @Test
  @SuppressWarnings("squid:S2925")
  public void testThatMappingFromTemplateIsApplied() throws Exception {
    registry.counter(name("test", "cache-evictions")).inc();
    reportAndRefresh();

    // somehow the cluster state is not immediately updated... need to check
    Thread.sleep(200);
    ClusterStateResponse clusterStateResponse =
        client()
            .admin()
            .cluster()
            .prepareState()
            .setRoutingTable(false)
            .setLocal(false)
            .setNodes(true)
            .setIndices(indexWithDate)
            .execute()
            .actionGet();

    org.assertj.core.api.Assertions.assertThat(
            clusterStateResponse.getState().getMetaData().getIndices().containsKey(indexWithDate))
        .isTrue();
    IndexMetaData indexMetaData =
        clusterStateResponse.getState().getMetaData().getIndices().get(indexWithDate);
    org.assertj.core.api.Assertions.assertThat(indexMetaData.getMappings().containsKey("counter"))
        .isTrue();
    Map<String, Object> properties =
        getAsMap(indexMetaData.mapping("counter").sourceAsMap(), "properties");
    Map<String, Object> mapping = getAsMap(properties, "name");
    org.assertj.core.api.Assertions.assertThat(mapping).containsKey("index");
    org.assertj.core.api.Assertions.assertThat(mapping.get("index").toString())
        .isEqualTo("not_analyzed");
  }
Ejemplo n.º 7
0
 @Test
 public void shutdownServerDoesNotRespond() {
   getDefaultServer().shutdown();
   Assertions.assertThat(getLastMessage()).isNull();
   sendMessage(new CorfuMsg(CorfuMsgType.PING));
   Assertions.assertThat(getLastMessage()).isNull();
 }
Ejemplo n.º 8
0
  @Test
  @BZ("1188702")
  public void testDeleteLogsByDate() {
    kieSession = createKSession(HUMAN_TASK);

    processInstanceList = startProcess(kieSession, HUMAN_TASK_ID, 4);

    TaskService taskService = getRuntimeEngine().getTaskService();

    // Delete the last two task logs
    for (int i = processInstanceList.size() - 1; i > 0; i--) {
      List<Long> taskIdList =
          taskService.getTasksByProcessInstanceId(processInstanceList.get(i).getId());
      Assertions.assertThat(taskIdList).hasSize(1);

      Task task = taskService.getTaskById(taskIdList.get(0));
      Assertions.assertThat(task).isNotNull();

      int resultCount =
          taskAuditService
              .auditTaskDelete()
              .date(task.getTaskData().getCreatedOn())
              .build()
              .execute();
      Assertions.assertThat(resultCount).isEqualTo(1);
    }
  }
Ejemplo n.º 9
0
  @Test
  public void should_expose_isDownloaded() {
    org.assertj.core.api.Assertions.assertThat(ITEM.isDownloaded()).isTrue();

    ITEM.setFileName(null);
    org.assertj.core.api.Assertions.assertThat(ITEM.isDownloaded()).isFalse();
  }
Ejemplo n.º 10
0
  @Test
  public void deleteLogsByVersion() {
    KieSession kieSession = createKSession(HELLO_WORLD_PROCESS);
    startProcess(kieSession, HELLO_WORLD_PROCESS_ID, 7);
    disposeRuntimeManager();
    kieSession = createKSession(HELLO_WORLD_PROCESS2);
    startProcess(kieSession, HELLO_WORLD_PROCESS2_ID, 2);

    // Delete all logs of version 1.1
    ProcessInstanceLogDeleteBuilder deleteBuilder =
        auditService.processInstanceLogDelete().processVersion("1.0");
    int deleteResult = deleteBuilder.build().execute();
    Assertions.assertThat(deleteResult).isEqualTo(7);

    // Make sure that the 1.1 version logs are gone
    List<ProcessInstanceLog> resultList =
        auditService.processInstanceLogQuery().processVersion("1.0").build().getResultList();
    Assertions.assertThat(resultList).hasSize(0);

    // Now check that 1.0 version logs are present
    resultList =
        auditService.processInstanceLogQuery().processVersion("1.1").build().getResultList();
    Assertions.assertThat(resultList).hasSize(2);
    Assertions.assertThat(resultList).extracting("processVersion").containsExactly("1.1", "1.1");
  }
Ejemplo n.º 11
0
  @Test
  public void should_expose_the_API_url() {
    org.assertj.core.api.Assertions.assertThat(ITEM.getProxyURLWithoutExtention())
        .isEqualTo("/api/podcast/1/items/1/download");

    org.assertj.core.api.Assertions.assertThat(ITEM.getProxyURL())
        .isEqualTo("/api/podcast/1/items/1/download.mp4");
  }
Ejemplo n.º 12
0
  @Test
  public void should_report_parent_podcast_cover() {
    org.assertj.core.api.Assertions.assertThat(ITEM.getCoverOfItemOrPodcast()).isSameAs(COVER);

    ITEM.setCover(null);
    org.assertj.core.api.Assertions.assertThat(ITEM.getCoverOfItemOrPodcast())
        .isSameAs(PODCAST_COVER);
  }
  @Test
  public void testUserExistsSystemProperties() {
    UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.SYSTEM);
    Assertions.assertThat(ldapUserGroupCallback).isNotNull();

    boolean userExists = ldapUserGroupCallback.existsUser("john");
    Assertions.assertThat(userExists).isTrue();
  }
  @Test
  public void testGroupExistsSystemProperties() {
    UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.SYSTEM);
    Assertions.assertThat(ldapUserGroupCallback).isNotNull();

    boolean groupExists = ldapUserGroupCallback.existsGroup("manager");
    Assertions.assertThat(groupExists).isTrue();
  }
  @Test
  public void testGroupsForUserSystemProperties() {
    UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.SYSTEM);
    Assertions.assertThat(ldapUserGroupCallback).isNotNull();

    List<String> userGroups = ldapUserGroupCallback.getGroupsForUser("john", null, null);
    Assertions.assertThat(userGroups).hasSize(1);
  }
Ejemplo n.º 16
0
  @Test
  public void should_report_parent_podcast_id() {
    org.assertj.core.api.Assertions.assertThat(ITEM.getPodcastId()).isEqualTo(PODCAST.getId());

    ITEM.setPodcast(null);
    org.assertj.core.api.Assertions.assertThat(ITEM.getPodcastId())
        .isNotEqualTo(PODCAST.getId())
        .isNull();
  }
Ejemplo n.º 17
0
  @Test
  public void should_get_the_local_path() {
    /* When */ Path localPath = ITEM.getLocalPath();
    /* Then */ org.assertj.core.api.Assertions.assertThat(localPath).hasFileName("fakeItem.mp4");

    /* When */ String localStringPath = ITEM.getLocalUri();
    /* Then */ org.assertj.core.api.Assertions.assertThat(localStringPath)
        .isEqualTo("/tmp/Fake Podcast/fakeItem.mp4");
  }
Ejemplo n.º 18
0
  @Test
  public void testDeleteLogsByProcessId() {
    kieSession = createKSession(HUMAN_TASK);

    processInstanceList = startProcess(kieSession, HUMAN_TASK_ID, 2);

    int deletedLogs = taskAuditService.auditTaskDelete().processId(HUMAN_TASK_ID).build().execute();
    Assertions.assertThat(deletedLogs).isEqualTo(2);
    Assertions.assertThat(getAllAuditTaskLogs()).hasSize(0);
  }
Ejemplo n.º 19
0
  private void testDeleteLogsByDateRange(Date startDate, Date endDate, boolean remove) {
    processInstanceList = new ArrayList<ProcessInstance>();
    kieSession = createKSession(HUMAN_TASK);

    processInstanceList.addAll(startProcess(kieSession, HUMAN_TASK_ID, 5));

    // Delete tasks created from date1 to date2.
    int resultCount = deleteAuditTaskInstanceLogs(startDate, endDate);
    Assertions.assertThat(resultCount).isEqualTo(remove ? 5 : 0);
    Assertions.assertThat(getAllAuditTaskLogs()).hasSize(remove ? 0 : 5);
  }
  @Test
  public void testThatTemplateIsAdded() throws Exception {
    GetIndexTemplatesResponse response =
        client().admin().indices().prepareGetTemplates("metrics_template").get();

    org.assertj.core.api.Assertions.assertThat(response.getIndexTemplates()).hasSize(1);
    IndexTemplateMetaData templateData = response.getIndexTemplates().get(0);
    org.assertj.core.api.Assertions.assertThat(templateData.order()).isEqualTo(0);
    org.assertj.core.api.Assertions.assertThat(templateData.getMappings().get("_default_"))
        .isNotNull();
  }
Ejemplo n.º 21
0
  @Test
  public void should_have_a_valid_url() {
    org.assertj.core.api.Assertions.assertThat(ITEM.hasValidURL()).isTrue();

    PODCAST.setType("send");
    ITEM.setUrl("");
    org.assertj.core.api.Assertions.assertThat(ITEM.hasValidURL()).isTrue();

    PODCAST.setType("Youtube");
    ITEM.setUrl("");
    org.assertj.core.api.Assertions.assertThat(ITEM.hasValidURL()).isFalse();
  }
  @Test
  public void testAssemblingWithModelMapper() {
    Category category = factory.createCategory(1L, "category1", "http://img.png");
    // Specify to use the default assembler based on ModelMapper
    // Passing the ModelMapper.class qualifier is the same that using AssemblerTypes.MODEL_MAPPER
    CategoryRepresentation representation =
        fluently.assemble(category).with(ModelMapper.class).to(CategoryRepresentation.class);

    Assertions.assertThat(representation.getId()).isEqualTo(1L);
    Assertions.assertThat(representation.getName()).isEqualTo("category1");
    Assertions.assertThat(representation.getUrlImg()).isEqualTo("http://img.png");
  }
  @Test
  public void testThatPercolationNotificationWorks() throws IOException, InterruptedException {
    SimpleNotifier notifier = new SimpleNotifier();

    MetricFilter percolationFilter =
        new MetricFilter() {
          @Override
          public boolean matches(String name, Metric metric) {
            return name.startsWith(prefix + ".foo");
          }
        };
    elasticsearchReporter =
        createElasticsearchReporterBuilder()
            .percolationFilter(percolationFilter)
            .percolationNotifier(notifier)
            .build();

    final Counter evictions = registry.counter("foo");
    evictions.inc(18);
    reportAndRefresh();

    QueryBuilder queryBuilder =
        QueryBuilders.boolQuery()
            .must(QueryBuilders.matchAllQuery())
            .filter(
                QueryBuilders.boolQuery()
                    .must(QueryBuilders.rangeQuery("count").gte(20))
                    .must(QueryBuilders.termQuery("name", prefix + ".foo")));
    String json = String.format("{ \"query\" : %s }", queryBuilder.buildAsBytes().toUtf8());
    client()
        .prepareIndex(indexWithDate, ".percolator", "myName")
        .setRefresh(true)
        .setSource(json)
        .execute()
        .actionGet();

    evictions.inc(1);
    reportAndRefresh();
    assertThat(notifier.metrics.size(), is(0));

    evictions.inc(2);
    reportAndRefresh();
    org.assertj.core.api.Assertions.assertThat(notifier.metrics.size()).isEqualTo(1);
    org.assertj.core.api.Assertions.assertThat(notifier.metrics).containsKey("myName");
    org.assertj.core.api.Assertions.assertThat(notifier.metrics.get("myName").name())
        .isEqualTo(prefix + ".foo");

    notifier.metrics.clear();
    evictions.dec(2);
    reportAndRefresh();
    org.assertj.core.api.Assertions.assertThat(notifier.metrics.size()).isEqualTo(0);
  }
 @Test
 public void should_pass_when_private_fields_differ_but_are_not_compared() {
   boolean allowedToUsePrivateFields = FieldSupport.comparison().isAllowedToUsePrivateFields();
   Assertions.setAllowComparingPrivateFields(false);
   TestClassWithRandomId actual = new TestClassWithRandomId("1", 1);
   TestClassWithRandomId other = new TestClassWithRandomId(null, 1);
   // s field is ignored because null in other, and id also because it is private without public
   // getter
   objects.assertIsEqualToIgnoringNullFields(
       someInfo(), actual, other, noFieldComparators(), defaultTypeComparators());
   // reset
   Assertions.setAllowComparingPrivateFields(allowedToUsePrivateFields);
 }
Ejemplo n.º 25
0
  @Test
  public void adaptedAuthenticationExceptionShouldHaveSameDetailMessage() {

    // Given
    AuthException authException = new AuthException("MESSAGE");

    // When
    AuthenticationException authenticationException = JaspiAdapters.adapt(authException);

    // Then
    Assertions.assertThat(authenticationException.getMessage()).isEqualTo("MESSAGE");
    Assertions.assertThat(authenticationException.getCause()).isNull();
  }
Ejemplo n.º 26
0
  @Test
  public void testFirstResult() {
    startHumanTaskProcess(6, "john's task", "john");

    List<TaskSummary> taskList =
        ejb.getTasksAssignedAsPotentialOwner(
            "john", null, null, new QueryFilter(2, 2, "t.name", true));
    logger.info("### Potential owner task list: " + taskList);
    Assertions.assertThat(taskList).hasSize(2);
    for (int i = 0; i < taskList.size(); i++) {
      Assertions.assertThat(taskList.get(i).getName()).isEqualTo("john's task " + (i + 1 + 2));
    }
  }
Ejemplo n.º 27
0
 @Test
 public void shouldNotCreateCpuPinningForVirtualNumaNodes() {
   for (VmNumaNode numaNode : vmNumaNodes) {
     numaNode.getVdsNumaNodeList().clear();
   }
   Map<String, Object> cpuPinning =
       NumaSettingFactory.buildCpuPinningWithNumaSetting(vmNumaNodes, vdsNumaNodes);
   Assertions.assertThat(cpuPinning).isEmpty();
   Map<String, Object> mapping =
       NumaSettingFactory.buildVmNumatuneSetting(NumaTuneMode.INTERLEAVE, vmNumaNodes);
   Assertions.assertThat(mapping)
       .doesNotContainKeys(VdsProperties.NUMA_TUNE_MODE, VdsProperties.NUMA_TUNE_NODESET);
 }
  @Test
  public void testThatTimestampFieldnameCanBeConfigured() throws Exception {
    elasticsearchReporter =
        createElasticsearchReporterBuilder().timestampFieldname("myTimeStampField").build();
    registry.counter(name("myMetrics", "cache-evictions")).inc();
    reportAndRefresh();

    SearchResponse searchResponse =
        client().prepareSearch(indexWithDate).setTypes("counter").execute().actionGet();
    org.assertj.core.api.Assertions.assertThat(searchResponse.getHits().totalHits()).isEqualTo(1);

    Map<String, Object> hit = searchResponse.getHits().getAt(0).sourceAsMap();
    org.assertj.core.api.Assertions.assertThat(hit).containsKey("myTimeStampField");
  }
  @Test
  public void testMergingWithModelMapper() {
    CategoryRepresentation representation =
        new CategoryRepresentation(2L, "category2", "http://img2.png");

    Category category = factory.createCategory(1L, "category1", "http://img.png");
    fluently.merge(representation).with(AssemblerTypes.MODEL_MAPPER).into(category);

    Assertions.assertThat(category.getEntityId())
        .isEqualTo(
            1L); // should not have changed (works because setEntityId() is in visibility package)
    Assertions.assertThat(category.getName()).isEqualTo("category2");
    Assertions.assertThat(category.getUrlImg()).isEqualTo("http://img2.png");
  }
Ejemplo n.º 30
0
  @Test
  public void testMaxResults() {
    startHumanTaskProcess(4, "john's task", "john");

    List<TaskSummary> taskList =
        ejb.getTasksAssignedAsPotentialOwner(
            "john", null, null, new QueryFilter(0, 2, "t.id", true));
    logger.info("### Potential owner task list: " + taskList);
    Assertions.assertThat(taskList).hasSize(2);

    taskList = ejb.getTasksOwned("john", new QueryFilter(0, 1, null, "en-UK", null));
    logger.info("### Owned task list: " + taskList);
    Assertions.assertThat(taskList.size()).isEqualTo(1);
  }