Java tutorial
/* Copyright 2015 Red Hat, Inc. and/or its affiliates. This file is part of lightblue. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.redhat.lightblue.crud.ldap; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import org.junit.BeforeClass; import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; import org.skyscreamer.jsonassert.JSONAssert; import com.fasterxml.jackson.databind.JsonNode; import com.redhat.lightblue.Response; import com.redhat.lightblue.crud.FindRequest; import com.redhat.lightblue.crud.InsertionRequest; import com.redhat.lightblue.ldap.test.LdapServerExternalResource; import com.redhat.lightblue.mongo.test.MongoServerExternalResource; import com.unboundid.ldap.sdk.Attribute; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ITCaseLdapCRUDController_Objects_Test extends AbstractLdapCRUDController { private static final String BASEDB_USERS = "ou=Users,dc=example,dc=com"; @BeforeClass public static void beforeClass() throws Exception { ldapServer.add(BASEDB_USERS, new Attribute[] { new Attribute("objectClass", "top"), new Attribute("objectClass", "organizationalUnit"), new Attribute("ou", "Users") }); System.setProperty("ldap.host", "localhost"); System.setProperty("ldap.port", String.valueOf(LdapServerExternalResource.DEFAULT_PORT)); System.setProperty("ldap.database", "test"); System.setProperty("ldap.personWithAddress.basedn", BASEDB_USERS); System.setProperty("mongo.host", "localhost"); System.setProperty("mongo.port", String.valueOf(MongoServerExternalResource.DEFAULT_PORT)); System.setProperty("mongo.database", "lightblue"); initLightblueFactory("./datasources.json", "./metadata/person-with-address-metadata.json"); } @Test public void test1PersonWithAddress_Insert() throws Exception { Response response = lightblueFactory.getMediator().insert(createRequest_FromResource(InsertionRequest.class, "./crud/insert/person-with-address-insert-single.json")); assertNotNull(response); assertNoErrors(response); assertNoDataErrors(response); assertEquals(1, response.getModifiedCount()); JsonNode entityData = response.getEntityData(); assertNotNull(entityData); JSONAssert.assertEquals("[{\"dn\":\"uid=john.doe," + BASEDB_USERS + "\"}]", entityData.toString(), false); } @Test public void test2PersonWithAddress_Find() throws Exception { Response response = lightblueFactory.getMediator().find( createRequest_FromResource(FindRequest.class, "./crud/find/person-with-address-find-single.json")); assertNotNull(response); assertNoErrors(response); assertNoDataErrors(response); assertEquals(1, response.getMatchCount()); JsonNode entityData = response.getEntityData(); assertNotNull(entityData); JSONAssert.assertEquals( "[{\"dn\":\"uid=john.doe," + BASEDB_USERS + "\",\"address\":{\"street\":\"123 Some St.\",\"postalCode\":12345,\"state\":\"NC\"}}]", entityData.toString(), true); } }