@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();
    }
  }
Ejemplo n.º 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);
  }
  @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());
  }
Ejemplo n.º 4
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);
  }
Ejemplo n.º 5
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();
   }
 }
Ejemplo n.º 7
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 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));
      }
    }
  }