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;
}
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;
}
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());
}
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());
}
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());
}
Aggregations