Example #1
1
  @Test
  public void submapToString() {

    for (int i = 0; i < 20; i++) {
      m.put(i, "aa" + i);
    }

    Map submap = m.subMap(10, true, 13, true);
    assertEquals("{10=aa10, 11=aa11, 12=aa12, 13=aa13}", submap.toString());
  }
Example #2
1
  @Ignore
  @Test
  public void prototypeLayerSync() throws Exception {
    Layer layer = map.getLayersInternal().get(2);
    map.getLayersInternal().remove(layer);

    // check what happens to legend item
    LayerLegendItem item = (LayerLegendItem) map.getLegend().get(1);
    Layer reference = item.getLayer();
    assertSame(layer, reference); // reference was not cleared
  }
Example #3
1
  @Ignore
  @Test
  public void testLegendBaseline() throws Exception {
    assertTrue("Folder", map.getLegend().get(0) instanceof Folder);

    Folder folder = (Folder) map.getLegend().get(0);

    assertSame(
        "Reference Resource 0",
        map.getLayersInternal().get(0),
        ((LayerLegendItem) folder.getItems().get(0)).getLayer());
    assertSame(
        "Reference Resource 1",
        map.getLayersInternal().get(1),
        ((LayerLegendItem) folder.getItems().get(1)).getLayer());

    assertSame(
        "Reference Resource 2",
        map.getLayersInternal().get(2),
        ((LayerLegendItem) map.getLegend().get(1)).getLayer());
    assertSame(
        "Reference Resource 3",
        map.getLayersInternal().get(3),
        ((LayerLegendItem) map.getLegend().get(2)).getLayer());
  }
 // A test that a room can be added to an empty map.
 @Test
 public void addToEmptyMap() {
   Map m = new Map();
   Room firstroom = Mockito.mock(Room.class);
   m.addRoom(firstroom);
   assertSame(firstroom, m.getLocation());
 }
 // Testing to getter functions. These return a member variable so they should
 // always be equal to the value of the member.
 @Test
 public void setLocationTest() {
   Map m = new Map();
   Room room = Mockito.mock(Room.class);
   m.setLocation(room);
   assertSame(room, m.getLocation());
 }
  static {
    String bibFilePath = testDataParentPath + File.separator + "mhldMergeBibs1346.mrc";
    try {
      RawRecordReader rawRecRdr = new RawRecordReader(new FileInputStream(new File(bibFilePath)));
      while (rawRecRdr.hasNext()) {
        RawRecord rawRec = rawRecRdr.next();
        Record rec = rawRec.getAsRecord(true, false, "999", "MARC8");
        String id = rec.getControlNumber();
        // String id = RecordTestingUtils.getRecordIdFrom001(rec);
        ALL_UNMERGED_BIBS.put(id, rec);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }

    bibFilePath = testDataParentPath + File.separator + "mhldMerged1346.mrc";
    try {
      RawRecordReader rawRecRdr = new RawRecordReader(new FileInputStream(new File(bibFilePath)));
      while (rawRecRdr.hasNext()) {
        RawRecord rawRec = rawRecRdr.next();
        Record rec = rawRec.getAsRecord(true, false, "999", "MARC8");
        String id = rec.getControlNumber();
        // String id = RecordTestingUtils.getRecordIdFrom001(rec);
        ALL_MERGED_BIB_RESULTS.put(id, rec);
      }
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    }
  }
Example #7
0
  @Test
  public void testEPL() {
    // should say fieldsTypes, maybe with object/component prefix
    Map<String, Object> eventTypes = new HashMap<>();
    eventTypes.put(LITERAL_SYMBOL, String.class);
    eventTypes.put(LITERAL_PRICE, Integer.class);

    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout(LITERAL_QUOTES, new RandomSentenceSpout());
    builder
        .setBolt(
            LITERAL_ESPER,
            (new EsperBolt())
                .addEventTypes(eventTypes)
                .addOutputTypes(
                    Collections.singletonMap(
                        LITERAL_RETURN_OBJ, Arrays.asList(LITERAL_AVG, LITERAL_PRICE)))
                .addStatements(
                    Collections.singleton(
                        "insert into Result "
                            + "select avg(price) as avg, price from "
                            + "quotes_default(symbol='A').win:length(2) "
                            + "having avg(price) > 60.0")))
        .shuffleGrouping(LITERAL_QUOTES);
    builder.setBolt("print", new PrinterBolt()).shuffleGrouping(LITERAL_ESPER, LITERAL_RETURN_OBJ);

    Config conf = new Config();
    LocalCluster cluster = new LocalCluster();
    cluster.submitTopology("test", conf, builder.createTopology());
    Utils.sleep(10000);
    cluster.shutdown();
    assertEquals(resultEPL.get(100), new Double(75.0));
    assertEquals(resultEPL.get(50), new Double(75.0));
  }
  @Test
  public void getProperties() throws Exception {
    final ModuleURN input = new ModuleURN("test:prov:me:A");
    final Map<String, Object> m = new HashMap<String, Object>();
    m.put("first", BigDecimal.TEN);
    m.put("second", "next");
    m.put("third", 909);
    // Test a non-empty and an empty map.
    List<Map<String, Object>> maps = Arrays.asList(m, new HashMap<String, Object>());
    for (Map<String, Object> map : maps) {
      final Map<String, Object> output = map;
      testAPI(
          new WSTester<Map<String, Object>>() {
            @Override
            protected Map<String, Object> invokeApi(boolean isNullParams) throws Exception {
              return getClient().getProperties(isNullParams ? null : input);
            }

            @Override
            protected Map<String, Object> setReturnValue(boolean isNullParams) {
              getMockSAService()
                  .setPropertiesOut(isNullParams ? null : new MapWrapper<String, Object>(output));
              return isNullParams ? null : output;
            }

            @Override
            protected void verifyInputParams(boolean isNullParams) throws Exception {
              verifyEquals(isNullParams ? null : input, getMockSAService().getURN());
            }
          });
      resetServiceParameters();
    }
  }
Example #9
0
  @Test
  public void testCookies_whenCookiesArePresent() {

    Collection<Cookie> cookies = new ArrayList<>();
    cookies.add(new Cookie("cookie1", "cookie1value"));
    cookies.add(new Cookie("cookie2", "cookie2value"));

    Map<String, String> expected = new HashMap<>();
    for (Cookie cookie : cookies) {
      expected.put(cookie.getName(), cookie.getValue());
    }

    Cookie[] cookieArray = cookies.toArray(new Cookie[cookies.size()]);

    when(servletRequest.getCookies()).thenReturn(cookieArray);

    assertTrue(
        "The count of cookies returned should be the same as those in the request",
        request.cookies().size() == 2);

    assertEquals(
        "A Map of Cookies should have been returned because they exist",
        expected,
        request.cookies());
  }
Example #10
0
 /** Test of renderChildren method, of class Activity. */
 @Test
 public void testCreateChildren() throws Exception {
   System.out.println("renderChildren");
   // Setup
   ChildPane childPane = new ChildPane();
   childPane.setChild("Child");
   VBox vbox = VBoxBuilder.create().children(childPane).build();
   Parent parent = new Parent();
   parent.setScene(vbox);
   Data data = new Data();
   Map<Field, Object> fieldParams = new HashMap<Field, Object>();
   for (Field field : data.getClass().getDeclaredFields()) {
     field.setAccessible(true);
     fieldParams.put(field, field.get(data));
   }
   RenderParameter renderParam = new RenderParameter();
   String id = renderParam.putParam("checkForLabel", "CheckForLabel");
   childPane.setId(id);
   parent.createChildren(fieldParams, renderParam, ValidationResult.getEmptyResult());
   // Assertoin
   Child child = (Child) parent.getChildActivities(Child.class).get(0);
   assertNotNull(child);
   assertNotNull(child.getScene());
   assertEquals(childPane, child.getScene());
   assertEquals(parent, child.getParent());
   VBox cvbox = (VBox) child.getScene().getChildren().get(0);
   assertTrue(cvbox.getChildren().get(0) instanceof Button);
   assertTrue(cvbox.getChildren().get(1) instanceof Label);
   assertEquals(data.checkForButton, ((Button) cvbox.getChildren().get(0)).getText());
   assertEquals("CheckForLabel", ((Label) cvbox.getChildren().get(1)).getText());
 }
  // FIXME: fails!  needs MarcCombiningReader for mhld or at least a diff version of RawRecordReader
  @Test
  public void testMultMHLDsWithSameID() throws IOException {
    // bib134, multMhlds1
    String bibFilePath = testDataParentPath + File.separator + "mhldMergeBibs134.mrc";
    String mhldFilePath = testDataParentPath + File.separator + "mhldMergeMhlds1Mult.mrc";
    Map<String, Record> mergedRecs =
        MergeSummaryHoldings.mergeMhldsIntoBibRecordsAsMap(bibFilePath, mhldFilePath);

    Record mergedRec = mergedRecs.get("a1");
    assertEquals("Expected three 852", 3, mergedRec.getVariableFields("852").size());
    Set<String> expectedVals = new HashSet<String>();
    expectedVals.add("Location1");
    expectedVals.add("Location2");
    RecordTestingUtils.assertSubfieldHasExpectedValues(mergedRec, "852", 'b', expectedVals);

    expectedVals.clear();
    expectedVals.add("(month)");
    expectedVals.add("(season)");
    RecordTestingUtils.assertSubfieldHasExpectedValues(mergedRec, "853", 'b', expectedVals);

    assertEquals("Expected one 863", 2, mergedRec.getVariableFields("863").size());
    assertEquals("Expected one 866", 1, mergedRec.getVariableFields("866").size());
    // fail("Implement me");
    System.out.println("Test testMultMHLDsWithSameID() successful");
  }
Example #12
0
 /** Test of initialize method, of class Activity. */
 @Test
 public void testInitialize_Activity_Map() throws Exception {
   System.out.println("initialize");
   // Setup
   ParentActivity parent = new ParentActivity();
   Data data = new Data();
   Map<Field, Object> fieldParams = new HashMap<Field, Object>();
   for (Field field : data.getClass().getDeclaredFields()) {
     field.setAccessible(true);
     fieldParams.put(field, field.get(data));
   }
   final String field2 = "field2value";
   final List<String> field3 = new ArrayList<String>();
   Map<String, Object> takeoverParams =
       new HashMap<String, Object>() {
         {
           put("field2", field2);
           put("field3", field3);
         }
       };
   ChildActivity child = new ChildActivity();
   child.initialize(parent, fieldParams, takeoverParams);
   // Assertion
   assertEquals(parent, child.getParent());
   assertEquals(data.getField0(), child.field0);
   assertEquals(data.getField1(), child.field1);
   assertEquals(field2, child.field2);
   assertEquals(field3, child.field3);
   assertEquals("TESTING", child.getTest());
 }
Example #13
0
  @Test
  @org.junit.Ignore
  public void large_node_size() {
    for (int i : new int[] {10, 200, 6000}) {

      int max = i * 100;
      File f = TT.tempDbFile();
      DB db = DBMaker.fileDB(f).transactionDisable().make();
      Map m =
          db.treeMapCreate("map")
              .nodeSize(i)
              .keySerializer(BTreeKeySerializer.INTEGER)
              .valueSerializer(Serializer.INTEGER)
              .make();

      for (int j = 0; j < max; j++) {
        m.put(j, j);
      }

      db.close();
      db = DBMaker.fileDB(f).deleteFilesAfterClose().transactionDisable().make();
      m = db.treeMap("map");

      for (Integer j = 0; j < max; j++) {
        assertEquals(j, m.get(j));
      }
      db.close();
    }
  }
  @Test
  public void readTest() {
    String insertKey = "user0";
    Map<String, ByteIterator> insertMap = insertRow(insertKey);
    HashSet<String> readFields = new HashSet<>();
    HashMap<String, ByteIterator> readResultMap = new HashMap<>();

    // Test reading a single field
    readFields.add("FIELD0");
    orientDBClient.read(CLASS, insertKey, readFields, readResultMap);
    assertEquals(
        "Assert that result has correct number of fields", readFields.size(), readResultMap.size());
    for (String field : readFields) {
      assertEquals(
          "Assert " + field + " was read correctly",
          insertMap.get(field).toString(),
          readResultMap.get(field).toString());
    }

    readResultMap = new HashMap<>();

    // Test reading all fields
    readFields.add("FIELD1");
    readFields.add("FIELD2");
    orientDBClient.read(CLASS, insertKey, readFields, readResultMap);
    assertEquals(
        "Assert that result has correct number of fields", readFields.size(), readResultMap.size());
    for (String field : readFields) {
      assertEquals(
          "Assert " + field + " was read correctly",
          insertMap.get(field).toString(),
          readResultMap.get(field).toString());
    }
  }
Example #15
0
  @Test
  public void getDistinctKeysAndCounts_SortByKeyDescending() {

    Connection connection = null;
    ResultSet resultSet = null;
    try {
      ConnectionManager connectionManager = temporaryFileDatabase.getConnectionManager(true);
      initWithTestData(connectionManager);

      connection = connectionManager.getConnection(null);
      resultSet = DBQueries.getDistinctKeysAndCounts(true, NAME, connection);

      Map<String, Integer> resultSetToMap = resultSetToMap(resultSet);
      assertEquals(3, resultSetToMap.size());

      Iterator<Map.Entry<String, Integer>> entriesIterator = resultSetToMap.entrySet().iterator();

      Map.Entry entry = entriesIterator.next();
      assertEquals("gps", entry.getKey());
      assertEquals(1, entry.getValue());

      entry = entriesIterator.next();
      assertEquals("airbags", entry.getKey());
      assertEquals(1, entry.getValue());

      entry = entriesIterator.next();
      assertEquals("abs", entry.getKey());
      assertEquals(2, entry.getValue());

    } finally {
      DBUtils.closeQuietly(resultSet);
      DBUtils.closeQuietly(connection);
    }
  }
 private MapMessage newMapMessage(Map<String, Object> body) throws JMSException {
   MapMessage message = new MapMessageImpl();
   for (String key : body.keySet()) {
     Object value = body.get(key);
     message.setObject(key, value);
   }
   return message;
 }
 // A test that a room can be added to a map with one room in it.
 @Test
 public void addToOneRoomTest() {
   Map m = new Map();
   Room firstroom = Mockito.mock(Room.class);
   Room secondroom = Mockito.mock(Room.class);
   m.addRoom(firstroom);
   m.addRoom(secondroom);
   assertSame(secondroom, m.getLocation().northRoom);
 }
Example #18
0
  @Test
  public void queryParamShouldBeParsedAsHashMap() {
    Map<String, String[]> params = new HashMap<>();
    params.put("user[name]", new String[] {"Federico"});

    when(servletRequest.getParameterMap()).thenReturn(params);

    String name = request.queryMap("user").value("name");
    assertEquals("Invalid name in query string", "Federico", name);
  }
 @Test
 public void getPuttedValueFromTheMap() {
   HazelcastClient hClient = getHazelcastClient();
   Map<String, String> clientMap = hClient.getMap("getPuttedValueFromTheMap");
   int size = clientMap.size();
   clientMap.put("1", "Z");
   String value = clientMap.get("1");
   assertEquals("Z", value);
   assertEquals(size + 1, clientMap.size());
 }
  @Test
  public void testParameterToPairsWhenValueIsCollection() throws Exception {
    Map<String, String> collectionFormatMap = new HashMap<String, String>();
    collectionFormatMap.put("csv", ",");
    collectionFormatMap.put("tsv", "\t");
    collectionFormatMap.put("ssv", " ");
    collectionFormatMap.put("pipes", "\\|");
    collectionFormatMap.put("", ","); // no format, must default to csv
    collectionFormatMap.put("unknown", ","); // all other formats, must default to csv

    String name = "param-a";

    List<Object> values = new ArrayList<Object>();
    values.add("value-a");
    values.add(123);
    values.add(new Date());

    // check for multi separately
    List<Pair> multiPairs = apiClient.parameterToPairs("multi", name, values);
    assertEquals(values.size(), multiPairs.size());

    // all other formats
    for (String collectionFormat : collectionFormatMap.keySet()) {
      List<Pair> pairs = apiClient.parameterToPairs(collectionFormat, name, values);

      assertEquals(1, pairs.size());

      String delimiter = collectionFormatMap.get(collectionFormat);
      String[] pairValueSplit = pairs.get(0).getValue().split(delimiter);

      // must equal input values
      assertEquals(values.size(), pairValueSplit.length);
    }
  }
 // [Issue#232]
 public void testBigDecimalAsPlainStringTreeConversion() throws Exception {
   ObjectMapper mapper = new ObjectMapper();
   mapper.enable(SerializationFeature.WRITE_BIGDECIMAL_AS_PLAIN);
   Map<String, Object> map = new HashMap<String, Object>();
   String PI_STR = "3.00000000";
   map.put("pi", new BigDecimal(PI_STR));
   JsonNode tree = mapper.valueToTree(map);
   assertNotNull(tree);
   assertEquals(1, tree.size());
   assertTrue(tree.has("pi"));
 }
Example #22
0
  @Test
  public void testPrimitiveAccess() {
    Map<String, Double> vpm = new HashMap<String, Double>();

    dp.setVehiclesPerMeter(vpm);

    Double val = 1.23;
    vpm.put("3", val);

    assertEquals((Double) 1.23, dp.getVehiclesPerMeter().get("3"));
  }
  private void doOperatorTask() throws ClassNotFoundException, IOException {
    BlockingTaskSummaryResponseHandler handler = new BlockingTaskSummaryResponseHandler();
    client.getTasksAssignedAsPotentialOwner("operator", "en-UK", handler);
    List<TaskSummary> sums = handler.getResults();
    assertNotNull(sums);
    assertEquals(1, sums.size());

    BlockingTaskOperationResponseHandler startTaskOperationHandler =
        new BlockingTaskOperationResponseHandler();
    client.start(sums.get(0).getId(), "operator", startTaskOperationHandler);

    BlockingGetTaskResponseHandler getTaskHandler = new BlockingGetTaskResponseHandler();
    client.getTask(sums.get(0).getId(), getTaskHandler);
    Task operatorTask = getTaskHandler.getTask();

    BlockingGetContentResponseHandler getContentHandler = new BlockingGetContentResponseHandler();
    client.getContent(operatorTask.getTaskData().getDocumentContentId(), getContentHandler);
    Content content = getContentHandler.getContent();

    assertNotNull(content);

    ByteArrayInputStream bais = new ByteArrayInputStream(content.getContent());
    ObjectInputStream ois = new ObjectInputStream(bais);
    Map<String, Object> deserializedContent = (Map<String, Object>) ois.readObject();
    Call restoredCall = (Call) deserializedContent.get("call");
    persistenceService.storeCall(restoredCall);

    Emergency emergency = new Emergency();

    emergency.setCall(restoredCall);

    emergency.setLocation(new Location(1, 2));
    emergency.setType(Emergency.EmergencyType.HEART_ATTACK);
    emergency.setNroOfPeople(1);
    persistenceService.storeEmergency(emergency);

    trackingService.attachEmergency(restoredCall.getId(), emergency.getId());

    Map<String, Object> info = new HashMap<String, Object>();
    info.put("emergency", emergency);

    ContentData result = new ContentData();
    result.setAccessType(AccessType.Inline);
    result.setType("java.util.Map");
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(bos);
    out.writeObject(info);
    out.close();
    result.setContent(bos.toByteArray());

    BlockingTaskOperationResponseHandler completeTaskOperationHandler =
        new BlockingTaskOperationResponseHandler();
    client.complete(sums.get(0).getId(), "operator", result, completeTaskOperationHandler);
  }
  @Test
  public void testMapEquals() {
    Map s = new HashMap();
    s.put("five", 5);
    s.put("ten", 10);

    Map r = new InstrumentedMap(s);
    Map q = new InstrumentedMap(r);

    assertTrue(r.equals(q));
  }
 // A test that a move north doesn't do anything if there is not a room.
 @Test
 public void illegalMoveNorthNoRoomTest() {
   Map map = new Map();
   Room loc = Mockito.mock(Room.class);
   Door door = Mockito.mock(Door.class);
   Mockito.when(loc.getNorthRoom()).thenReturn(null);
   Mockito.when(loc.getNorthDoor()).thenReturn(door);
   map.setLocation(loc);
   map.moveNorth(loc);
   assertEquals(loc, map.getLocation());
 }
 // A test that a move south doesn't do anything if there is not a door there.
 @Test
 public void illegalMoveSouthNoDoorTest() {
   Map map = new Map();
   Room loc = Mockito.mock(Room.class);
   Room loc2 = Mockito.mock(Room.class);
   Mockito.when(loc.getSouthRoom()).thenReturn(loc2);
   Mockito.when(loc.getSouthDoor()).thenReturn(null);
   map.setLocation(loc);
   map.moveSouth(loc);
   assertEquals(loc, map.getLocation());
 }
Example #27
0
 @Test
 public void in_memory_test() {
   StorageDirect engine = new StorageDirect(Volume.memoryFactory(false));
   Map<Long, Integer> recids = new HashMap<Long, Integer>();
   for (int i = 0; i < 1000; i++) {
     long recid = engine.recordPut(i, Serializer.BASIC_SERIALIZER);
     recids.put(recid, i);
   }
   for (Long recid : recids.keySet()) {
     assertEquals(recids.get(recid), engine.recordGet(recid, Serializer.BASIC_SERIALIZER));
   }
 }
 // A test if a move south works if there is a door and room to the south.
 @Test
 public void legalMoveSouthTest() {
   Map map = new Map();
   Room loc = Mockito.mock(Room.class);
   Room loc2 = Mockito.mock(Room.class);
   Door door = Mockito.mock(Door.class);
   Mockito.when(loc.getSouthRoom()).thenReturn(loc2);
   Mockito.when(loc.getSouthDoor()).thenReturn(door);
   map.setLocation(loc);
   map.moveSouth(loc);
   assertEquals(loc2, map.getLocation());
 }
  @Test
  public void testLong() {
    DB db = DBMaker.memoryDB().make();
    Map m = db.treeMap("test").keySerializer(Serializer.LONG).createOrOpen();

    for (long i = 0; i < 1000; i++) {
      m.put(i * i, i * i + 1);
    }

    for (long i = 0; i < 1000; i++) {
      assertEquals(i * i + 1, m.get(i * i));
    }
  }
Example #30
0
  @Test
  public void testQueryParams() {

    Map<String, String[]> params = new HashMap<>();
    params.put("sort", new String[] {"asc"});
    params.put("items", new String[] {"10"});

    when(servletRequest.getParameterMap()).thenReturn(params);

    Set<String> result = request.queryParams();

    assertArrayEquals(
        "Should return the query parameter names", params.keySet().toArray(), result.toArray());
  }