Search in sources :

Example 21 with Service

use of io.github.microcks.domain.Service in project microcks by microcks.

the class ServiceRepositoryImpl method findByIdIn.

@Override
public List<Service> findByIdIn(List<String> ids) {
    // Convert ids into BSON ObjectId.
    List<ObjectId> objIds = new ArrayList<ObjectId>();
    for (String id : ids) {
        objIds.add(new ObjectId(id));
    }
    List<Service> results = template.find(new Query(Criteria.where("_id").in(objIds)), Service.class);
    return results;
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) ObjectId(org.bson.types.ObjectId) ArrayList(java.util.ArrayList) Service(io.github.microcks.domain.Service)

Example 22 with Service

use of io.github.microcks.domain.Service in project microcks by microcks.

the class ServiceRepositoryImpl method findByLabels.

@Override
public List<Service> findByLabels(Map<String, String> labels) {
    Query query = new Query();
    for (String labelKey : labels.keySet()) {
        query.addCriteria(Criteria.where("metadata.labels." + labelKey).is(labels.get(labelKey)));
    }
    List<Service> results = template.find(query, Service.class);
    return results;
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Service(io.github.microcks.domain.Service)

Example 23 with Service

use of io.github.microcks.domain.Service in project microcks by microcks.

the class GenericResourceRepositoryTest method testCreateGenericResource.

@Test
public void testCreateGenericResource() {
    // Create a minimal service.
    Service service = new Service();
    service.setName("DynamicAPI");
    service.setVersion("1.0");
    serviceRepository.save(service);
    // Define a JSON payload to put into a GenericResource associated to service.
    String jsonString = "{ \"foo\": 1234, \"bar\": \"string value\" }";
    GenericResource resource = new GenericResource();
    resource.setServiceId(service.getId());
    resource.setPayload(Document.parse(jsonString));
    // Save to repository.
    GenericResource dynaResource = repository.save(resource);
    // Test some manipulations of the payload Document.
    Document payload = dynaResource.getPayload();
    payload.append("id", dynaResource.getId());
    assertTrue(1234 == payload.getInteger("foo"));
    assertEquals("string value", payload.getString("bar"));
    assertEquals(dynaResource.getId(), payload.getString("id"));
    // Adding more resources before querying.
    jsonString = "{ \"foo\": 1234, \"bar\": \"other value\" }";
    GenericResource resource1 = new GenericResource();
    resource1.setServiceId(service.getId());
    resource1.setPayload(Document.parse(jsonString));
    repository.save(resource1);
    jsonString = "{ \"foo\": 1235, \"bar\": \"other value\" }";
    GenericResource resource2 = new GenericResource();
    resource2.setServiceId(service.getId());
    resource2.setPayload(Document.parse(jsonString));
    repository.save(resource2);
    // Query by example using 1 field.
    List<GenericResource> dynaResources = repository.findByServiceIdAndJSONQuery(service.getId(), "{ \"foo\": 1234 }");
    assertEquals(2, dynaResources.size());
    for (GenericResource r : dynaResources) {
        assertTrue(resource.getId().equals(r.getId()) || resource1.getId().equals(r.getId()));
    }
    // Query by example using 1 other field value.
    dynaResources = repository.findByServiceIdAndJSONQuery(service.getId(), "{ \"foo\": 1235 }");
    assertEquals(1, dynaResources.size());
    assertEquals(resource2.getId(), dynaResources.get(0).getId());
    // Query by example using 2 fields.
    dynaResources = repository.findByServiceIdAndJSONQuery(service.getId(), "{ \"foo\": 1234, \"bar\": \"other value\"}");
    assertEquals(1, dynaResources.size());
    assertEquals(resource1.getId(), dynaResources.get(0).getId());
    // Query by example using 1 field with complex expression.
    dynaResources = repository.findByServiceIdAndJSONQuery(service.getId(), "{ \"foo\": {$gt: 1234, $lt: 1236} }");
    assertEquals(1, dynaResources.size());
    assertEquals(resource2.getId(), dynaResources.get(0).getId());
}
Also used : GenericResource(io.github.microcks.domain.GenericResource) Service(io.github.microcks.domain.Service) Document(org.bson.Document) Test(org.junit.Test)

Example 24 with Service

use of io.github.microcks.domain.Service in project microcks by microcks.

the class ServiceRepositoryTest method testFindByNameAndVersion.

@Test
public void testFindByNameAndVersion() {
    Service service = repository.findByNameAndVersion("HelloWorld", "1.2");
    assertNotNull(service);
    assertEquals("HelloWorld", service.getName());
    assertEquals("1.2", service.getVersion());
}
Also used : Service(io.github.microcks.domain.Service) Test(org.junit.Test)

Example 25 with Service

use of io.github.microcks.domain.Service in project microcks by microcks.

the class ServiceRepositoryTest method testFindByNameLike.

@Test
public void testFindByNameLike() {
    List<Service> services = repository.findByNameLike("world");
    assertTrue(!services.isEmpty());
    assertEquals(2, services.size());
    for (Service service : services) {
        assertEquals("HelloWorld", service.getName());
    }
    services = repository.findByNameLike("Hello");
    assertTrue(!services.isEmpty());
    assertEquals(3, services.size());
}
Also used : Service(io.github.microcks.domain.Service) Test(org.junit.Test)

Aggregations

Service (io.github.microcks.domain.Service)42 MockRepositoryImportException (io.github.microcks.util.MockRepositoryImportException)18 Operation (io.github.microcks.domain.Operation)15 Test (org.junit.Test)15 Resource (io.github.microcks.domain.Resource)12 IOException (java.io.IOException)10 ResponseEntity (org.springframework.http.ResponseEntity)7 Response (io.github.microcks.domain.Response)6 File (java.io.File)6 ArrayList (java.util.ArrayList)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Exchange (io.github.microcks.domain.Exchange)4 Request (io.github.microcks.domain.Request)4 RequestResponsePair (io.github.microcks.domain.RequestResponsePair)4 UnidirectionalEvent (io.github.microcks.domain.UnidirectionalEvent)4 List (java.util.List)4 HttpHeaders (org.springframework.http.HttpHeaders)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 Header (io.github.microcks.domain.Header)3 Metadata (io.github.microcks.domain.Metadata)3