@Test
  public void checkHappyPathStreamStoreOperations() {

    try {
      cassandraConnector.saveStreamDefinitionToStore(getCluster(), streamDefinition1);
    } catch (StreamDefinitionStoreException e) {
      e.printStackTrace();
      fail();
    }

    StreamDefinition streamDefinitionFromStore = null;
    try {
      Credentials credentials = getCredentials(cluster);
      streamDefinitionFromStore =
          cassandraConnector.getStreamDefinitionFromCassandra(
              getCluster(), streamDefinition1.getStreamId());
    } catch (Exception e) {
      e.printStackTrace();
      fail();
    }
    assertEquals(streamDefinition1, streamDefinitionFromStore);
    List<Event> eventList =
        EventConverterUtils.convertFromJson(
            CassandraTestConstants.properEvent, streamDefinition1.getStreamId());
    try {
      int eventCounter = 0;
      for (Event event : eventList) {
        insertEvent(cluster, event, eventCounter++);
      }
    } catch (Exception e) {
      e.printStackTrace();
      fail();
    }
  }
Пример #2
0
  @Test
  public void updateUser() {
    boolean thrown = false;
    WebResource webResource = resource();

    try {
      JSONObject user =
          webResource
              .path("resources/users/testuid")
              .accept("application/json")
              .get(JSONObject.class);

      user.put("password", "NEW PASSWORD")
          .put("email", "*****@*****.**")
          .put("username", "UPDATED TEST USER");
      webResource.path("resources/users/testuid").type("application/json").put(user);

      user =
          webResource
              .path("resources/users/testuid")
              .accept("application/json")
              .get(JSONObject.class);

      assertEquals(user.get("username"), "UPDATED TEST USER");
      assertEquals(user.get("email"), "*****@*****.**");
      assertEquals(user.get("password"), "NEW PASSWORD");

    } catch (Exception e) {
      e.printStackTrace();
      thrown = true;
    }

    assertFalse(thrown);
  }
Пример #3
0
  @Test
  @ElasticsearchIndex(indexName = "twitter")
  public void updateWithValidParameters() {
    String script =
        "{\n"
            + "    \"script\" : \"ctx._source.tags += tag\",\n"
            + "    \"params\" : {\n"
            + "        \"tag\" : \"blue\"\n"
            + "    }\n"
            + "}";
    try {

      Index index =
          new Index.Builder("{\"user\":\"kimchy\", \"tags\":\"That is test\"}")
              .index("twitter")
              .type("tweet")
              .id("1")
              .build();
      index.addParameter(Parameters.REFRESH, true);
      client.execute(index);

      JestResult result =
          client.execute(new Update.Builder(script).index("twitter").type("tweet").id("1").build());
      assertNotNull(result);
      assertTrue(result.isSucceeded());

      JestResult getResult =
          client.execute(new Get.Builder("1").index("twitter").type("tweet").build());
      assertEquals("That is testblue", ((Map) getResult.getValue("_source")).get("tags"));

    } catch (Exception e) {
      fail("Failed during the update with valid parameters. Exception:" + e.getMessage());
    }
  }
 /** Verify constructor */
 @Test
 public void testConstructor() {
   try {
     new SCMProjectProperty(null);
     fail("Null should be handled by SCMProjectProperty constructor.");
   } catch (Exception e) {
     assertEquals(BaseProjectProperty.INVALID_JOB_EXCEPTION, e.getMessage());
   }
 }
Пример #5
0
  @Test
  public void shouldNotThrowExceptionIfXmlnsNotRecognized() {
    Map<String, String> motherFormValuesWithoutXmlns =
        motherFormValues(
            "94d5374f-290e-409f-bc57-86c2e4bcc43f", "89fda0284e008d2e0c980fb13fa0e5bb");
    motherFormValuesWithoutXmlns.put("xmlns", "randomurl");

    try {
      careService.processAndSaveForms(
          motherFormValuesWithoutXmlns, new ArrayList<Map<String, String>>());
    } catch (Exception e) {
      fail("The exception should not have been thrown: " + e.getMessage());
    }
  }
Пример #6
0
  // ugly.. but separation into separate test cases would be probably uglier
  @Test
  public void getUserBookmarkList() {
    boolean thrown = false;

    try {
      WebResource webResource = resource();
      JSONObject user =
          webResource
              .path("resources/users/testuid")
              .accept("application/json")
              .get(JSONObject.class);
      assertTrue(user != null);

      webResource = client().resource(user.getString("bookmarks"));

      JSONObject bookmark = new JSONObject();
      bookmark
          .put("uri", "http://java.sun.com")
          .put("sdesc", "test desc")
          .put("ldesc", "long test description");
      webResource.type("application/json").post(bookmark);

      JSONArray bookmarks = webResource.accept("application/json").get(JSONArray.class);
      assertTrue(bookmarks != null);
      int bookmarksSize = bookmarks.length();

      String testBookmarkUrl = bookmarks.getString(0);
      WebResource bookmarkResource = client().resource(testBookmarkUrl);

      bookmark = bookmarkResource.accept("application/json").get(JSONObject.class);
      assertTrue(bookmark != null);

      bookmarkResource.delete();

      bookmarks =
          resource()
              .path("resources/users/testuid/bookmarks")
              .accept("application/json")
              .get(JSONArray.class);
      assertTrue(bookmarks != null);
      assertTrue(bookmarks.length() == (bookmarksSize - 1));

    } catch (Exception e) {
      e.printStackTrace();
      thrown = true;
    }

    assertFalse(thrown);
  }
Пример #7
0
  @Test
  public void deleteUser() {
    boolean thrown = false;
    WebResource webResource = resource();
    JSONObject user = new JSONObject();

    try {
      webResource.path("resources/users/testuid").delete();
    } catch (Exception e) {
      e.printStackTrace();
      thrown = true;
    }

    assertFalse(thrown);
  }
 @Before
 public void setUpProductCatalogue() {
   try {
     new CoreBasicDataCreator().createEssentialData(Collections.EMPTY_MAP, null);
     importCsv("/merchandisefulfilmentprocess/test/testBasics.csv", "windows-1252");
     importCsv("/merchandisefulfilmentprocess/test/testCatalog.csv", "windows-1252");
     baseSiteService.setCurrentBaseSite(baseSiteService.getBaseSiteForUID("testSite"), false);
     LOG.warn("Catalogue has been imported");
   } catch (final ImpExException e) {
     LOG.warn("Catalogue import has failed");
     e.printStackTrace();
   } catch (final Exception e) {
     LOG.warn("createEssentialData(...) has failed");
     e.printStackTrace();
   }
 }
Пример #9
0
  @Test
  public void createUser() {
    boolean thrown = false;
    WebResource webResource = resource();
    JSONObject user = new JSONObject();

    try {
      user.put("userid", "testuid")
          .put("password", "test")
          .put("email", "*****@*****.**")
          .put("username", "Test User");
      webResource.path("resources/users/testuid").type("application/json").put(user);
    } catch (Exception e) {
      e.printStackTrace();
      thrown = true;
    }

    assertFalse(thrown);
  }
  @Test
  public void informationModel() throws Exception {
    String serviceUrl = "http://service.url";
    GridDataService dataService = new GridDataService();
    dataService.setUrl(serviceUrl);
    getGridServiceDao().save(dataService);
    Metadata meta = new Metadata();

    try {
      meta.dmodel =
          MetadataUtils.deserializeDomainModel(new FileReader("test/data/cabioModelSnippet.xml"));
      meta.smeta =
          MetadataUtils.deserializeServiceMetadata(
              new FileReader("test/data/cabioServiceMetadata.xml"));
    } catch (Exception ex) {
      fail("Error deserializing test data: " + ex.getMessage());
      ex.printStackTrace();
    }
    try {
      getMetadataListener().loadMetadata(dataService, meta);
    } catch (Exception ex) {
      fail("Error loading metadata: " + ex.getMessage());
      ex.printStackTrace();
    }

    ServiceMetadataCatalogEntryBuilder b =
        (ServiceMetadataCatalogEntryBuilder)
            getApplicationContext().getBean("serviceMetadataCatalogEntryBuilder");

    final GridServiceEndPointCatalogEntry endpointCe = b.build(dataService);
    assertTrue(endpointCe instanceof GridDataServiceEndPointCatalogEntry);

    InformationModelCatalogEntryDao infoDao =
        (InformationModelCatalogEntryDao)
            TestDB.getApplicationContext().getBean("informationModelCatalogEntryDao");

    assertEquals(1, infoDao.getAll().size());

    InformationModelCatalogEntry infoEntry = (InformationModelCatalogEntry) infoDao.getAll().get(0);
    infoEntry.setAuthor(pUser);
    infoDao.save(infoEntry);

    GridServiceEndPointCatalogEntry endpointCe2 = b.build(dataService);
    assertEquals(endpointCe.getId(), endpointCe2.getId());

    assertEquals("Duplicate Information Model CE is being created", 1, infoDao.getAll().size());
  }
  @Test
  @ElasticsearchIndex(
      indexName = "histogram_facet",
      mappings = {
        @ElasticsearchMapping(
            typeName = "document",
            properties = {
              @ElasticsearchMappingField(
                  name = "quantity",
                  store = ElasticsearchMappingField.Store.Yes,
                  type = ElasticsearchMappingField.Types.Integer)
            })
      })
  public void testQuery() {

    String query =
        "{\n"
            + "    \"query\" : {\n"
            + "        \"match_all\" : {}\n"
            + "    },\n"
            + "    \"facets\" : {\n"
            + "        \"histo1\" : {\n"
            + "            \"histogram\" : {\n"
            + "                \"field\" : \"quantity\",\n"
            + "                \"interval\" : 100\n"
            + "            }\n"
            + "        }\n"
            + "    }\n"
            + "}";

    try {

      for (int i = 0; i < 2; i++) {
        Index index =
            new Index.Builder("{\"quantity\":\"910\"}")
                .index("histogram_facet")
                .type("document")
                .build();
        index.addParameter(Parameters.REFRESH, true);
        client.execute(index);
      }

      Index index =
          new Index.Builder("{\"quantity\":\"800\"}")
              .index("histogram_facet")
              .type("document")
              .build();
      index.addParameter(Parameters.REFRESH, true);
      client.execute(index);

      index =
          new Index.Builder("{\"quantity\":\"1110\"}")
              .index("histogram_facet")
              .type("document")
              .build();
      index.addParameter(Parameters.REFRESH, true);
      client.execute(index);

      Search search =
          (Search)
              new Search.Builder(query)
                  .addIndexName("histogram_facet")
                  .addIndexType("document")
                  .build();
      JestResult result = client.execute(search);
      List<HistogramFacet> histogramFacets = result.getFacets(HistogramFacet.class);

      assertEquals(1, histogramFacets.size());
      HistogramFacet histogramFacetFirst = histogramFacets.get(0);
      assertEquals("histo1", histogramFacetFirst.getName());

      List<HistogramFacet.Histogram> histograms = histogramFacetFirst.getHistograms();
      assertEquals(3, histograms.size());
      assertTrue(1L == histograms.get(0).getCount());
      assertTrue(800L == histograms.get(0).getKey());
      assertTrue(2L == histograms.get(1).getCount());
      assertTrue(900L == histograms.get(1).getKey());
      assertTrue(1L == histograms.get(2).getCount());
      assertTrue(1100L == histograms.get(2).getKey());

    } catch (Exception e) {
      fail("Failed during facet tests " + e.getMessage());
    }
  }
  @Test
  public void insertEventsFromMultipleStreams() {
    try {
      // save stream defn 1
      cassandraConnector.saveStreamDefinitionToStore(getCluster(), streamDefinition1);

      // save stream defn 3
      cassandraConnector.saveStreamDefinitionToStore(getCluster(), streamDefinition3);
    } catch (StreamDefinitionStoreException e) {
      e.printStackTrace();
      fail();
    }

    List<Event> eventList = new ArrayList<Event>();
    // retrieve stream id 1
    eventList.addAll(
        EventConverterUtils.convertFromJson(
            CassandraTestConstants.multipleProperEvent1, streamDefinition1.getStreamId()));

    // retrieve stream id 3
    eventList.addAll(
        EventConverterUtils.convertFromJson(
            CassandraTestConstants.multipleProperEvent3, streamDefinition3.getStreamId()));

    Map<String, Event> insertedEvents = new HashMap<String, Event>();
    int eventCounter = 0;
    for (Event event : eventList) {
      try {
        String rowKey = insertEvent(cluster, event, eventCounter++);
        // inserts row key only if event is valid, i.e. only proper events will add a row key
        insertedEvents.put(rowKey, event);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    assertEquals(4, insertedEvents.size());

    Map<String, Event> retrievedEvents = new HashMap<String, Event>();

    for (Map.Entry<String, Event> eventProps : insertedEvents.entrySet()) {
      try {
        retrievedEvents.put(
            eventProps.getKey(),
            getEvent(cluster, eventProps.getValue().getStreamId(), eventProps.getKey()));
      } catch (EventProcessingException e) {
        e.printStackTrace();
        fail();
      }
    }

    for (Map.Entry<String, Event> rowKeyAndEvent : retrievedEvents.entrySet()) {
      Event retrievedEvent = rowKeyAndEvent.getValue();
      Event originialEvent = insertedEvents.get(rowKeyAndEvent.getKey());
      System.out.println(
          "Retrieved Event : " + retrievedEvent + "\n Original Event : " + originialEvent + "\n\n");
      if (streamDefinition1.getStreamId().equals(originialEvent.getStreamId())) {
        assertTrue(DataBridgeUtils.equals(originialEvent, retrievedEvent, streamDefinition1));
      } else if (streamDefinition2.getStreamId().equals(originialEvent.getStreamId())) {
        assertTrue(DataBridgeUtils.equals(originialEvent, retrievedEvent, streamDefinition3));
      }
    }
  }