public Map<String, Object> buildMessage() {
   Map<String, Object> map = new HashMap<>();
   map.put("publisher", "norbert");
   map.put("time", NOW);
   map.put("readings", SAMPLE_READINGS);
   return map;
 }
 @Test
 public void setMetadata() throws IOException {
   expectStatusCode(202);
   Map<String, Object> metadata = new TreeMap<String, Object>();
   metadata.put("Year", "1989");
   metadata.put("Company", "42 BV");
   object.setMetadata(metadata);
   verifyHeaderValue("1989", X_OBJECT_META_PREFIX + "Year");
   verifyHeaderValue("42 BV", X_OBJECT_META_PREFIX + "Company");
 }
Esempio n. 3
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());
    }
  }
 @SuppressWarnings("EqualsBetweenInconvertibleTypes")
 @Test
 public void compareContainers() {
   Container container = account.getContainer("alpha");
   StoredObject object1 = container.getObject("img1.png");
   StoredObject object2 = container.getObject("img2.png");
   assertFalse(object1.equals("alpha"));
   assertFalse(object1.equals(object2));
   Map<StoredObject, String> containers = new TreeMap<StoredObject, String>();
   containers.put(object1, object1.getName());
   containers.put(object2, object2.getName());
   assertEquals(object1.getName(), containers.get(object1));
   assertEquals(object2.getName(), containers.get(object2));
   assertEquals(object1.getName().hashCode(), object1.hashCode());
 }
Esempio n. 5
0
 private Map<String, String> motherFormValues(String caseId, String flwId) {
   Map<String, String> motherForm = new HashMap<>();
   motherForm.put("xmlns", "http://bihar.commcarehq.org/pregnancy/new");
   motherForm.put("dateModified", "2012-07-21T12:02:59.923+05:30");
   motherForm.put(
       "fullName",
       "&#2327;&#2366;&#2351;&#2340;&#2381;&#2352;&#2368; &#2342;&#2375;&#2357;&#2368;");
   motherForm.put(
       "husbandName",
       "&#2342;&#2367;&#2344;&#2375;&#2358; &#2350;&#2369;&#2326;&#2367;&#2351;&#2366;");
   motherForm.put("hhNumber", "165");
   motherForm.put("familyNumber", "5");
   motherForm.put("dobKnown", "no");
   motherForm.put("caste", "other");
   motherForm.put("ageCalc", null);
   motherForm.put("instanceId", "e34707f8-80c8-4198-bf99-c11c90ba5c98");
   motherForm.put("motherCase", caseId);
   motherForm.put("flw", flwId);
   motherForm.put("timeStart", "2012-07-21T11:59:31.076+05:30");
   motherForm.put("timeEnd", "2012-07-21T12:02:59.923+05:30");
   return motherForm;
 }
  @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));
      }
    }
  }