Search in sources :

Example 1 with Animal

use of com.tvd12.calabash.local.test.mappersist.Animal in project calabash by youngmonkeys.

the class LocalMapAnimalPersistExample method test.

@SuppressWarnings("rawtypes")
public void test() throws Exception {
    SimpleSettings settings = new SimpleSettings();
    SimpleEntityMapPersistSetting mapPersistSetting = new SimpleEntityMapPersistSetting();
    mapPersistSetting.setWriteDelay(0);
    SimpleEntityMapSetting mapSetting = new SimpleEntityMapSetting();
    mapSetting.setMapName(CollectionNames.ANIMAL);
    mapSetting.setPersistSetting(mapPersistSetting);
    settings.addMapSetting(mapSetting);
    EzyBeanContext beanContext = newBeanContext();
    SimpleEntityMapPersistFactory.Builder mapPersistFactoryBuilder = SimpleEntityMapPersistFactory.builder();
    List mapPersistences = beanContext.getSingletons(MapPersistence.class);
    for (Object mapPersist : mapPersistences) {
        String mapName = MapPersistenceAnnotations.getMapName(mapPersist);
        mapPersistFactoryBuilder.addMapPersist(mapName, (EntityMapPersist) mapPersist);
    }
    Calabash calabash = new CalabashBuilder().settings(settings).mapPersistFactory(mapPersistFactoryBuilder.build()).build();
    Animal animal = new Animal(2, "animal 2", "cat");
    EntityMap<Long, Animal> entityMap = calabash.getEntityMap(CollectionNames.ANIMAL);
    entityMap.put(animal.getId(), animal);
    AnimalByNickQuery query = new AnimalByNickQuery(animal.getNick());
    Animal animalByQuery = entityMap.getByQuery(1L, query);
    System.out.println("animal by query: " + animalByQuery);
    Map<String, Object> statistics = new HashMap<>();
    // noinspection InfiniteLoopStatement
    while (true) {
        // noinspection BusyWait
        Thread.sleep(1000);
        ((StatisticsAware) calabash).addStatistics(statistics);
        System.out.println("statistics: " + statistics);
    }
}
Also used : SimpleEntityMapSetting(com.tvd12.calabash.local.setting.SimpleEntityMapSetting) SimpleSettings(com.tvd12.calabash.local.setting.SimpleSettings) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) HashMap(java.util.HashMap) SimpleEntityMapPersistSetting(com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting) CalabashBuilder(com.tvd12.calabash.local.CalabashBuilder) Animal(com.tvd12.calabash.local.test.mappersist.Animal) List(java.util.List) StatisticsAware(com.tvd12.calabash.core.statistic.StatisticsAware) Calabash(com.tvd12.calabash.Calabash) SimpleEntityMapPersistFactory(com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)

Example 2 with Animal

use of com.tvd12.calabash.local.test.mappersist.Animal in project ezyhttp by youngmonkeys.

the class ResponseEntityTest method createByStatusHeadersAndBody.

@Test
public void createByStatusHeadersAndBody() {
    // given
    int status = StatusCodes.ACCEPTED;
    Map<String, List<String>> headers = new HashMap<>();
    headers.put("hello", Arrays.asList("world", "galaxy"));
    headers.put("foo", Arrays.asList("bar", "animal"));
    Object body = "Hello World";
    // when
    ResponseEntity sut = new ResponseEntity(status, headers, body);
    // then
    Asserts.assertEquals(status, sut.getStatus());
    Asserts.assertEquals(new MultiValueMap(headers), sut.getHeaders());
    Asserts.assertEquals("world", sut.getHeader("hello"));
    Asserts.assertEquals(body, sut.getBody());
}
Also used : ResponseEntity(com.tvd12.ezyhttp.core.response.ResponseEntity) HashMap(java.util.HashMap) List(java.util.List) MultiValueMap(com.tvd12.ezyhttp.core.data.MultiValueMap) Test(org.testng.annotations.Test)

Aggregations

HashMap (java.util.HashMap)2 List (java.util.List)2 Calabash (com.tvd12.calabash.Calabash)1 StatisticsAware (com.tvd12.calabash.core.statistic.StatisticsAware)1 CalabashBuilder (com.tvd12.calabash.local.CalabashBuilder)1 SimpleEntityMapPersistSetting (com.tvd12.calabash.local.setting.SimpleEntityMapPersistSetting)1 SimpleEntityMapSetting (com.tvd12.calabash.local.setting.SimpleEntityMapSetting)1 SimpleSettings (com.tvd12.calabash.local.setting.SimpleSettings)1 Animal (com.tvd12.calabash.local.test.mappersist.Animal)1 SimpleEntityMapPersistFactory (com.tvd12.calabash.persist.factory.SimpleEntityMapPersistFactory)1 EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)1 MultiValueMap (com.tvd12.ezyhttp.core.data.MultiValueMap)1 ResponseEntity (com.tvd12.ezyhttp.core.response.ResponseEntity)1 Test (org.testng.annotations.Test)1