import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.onap.policy.rest.jpa.PolicyEntity;
import org.onap.policy.rest.jpa.PolicyRoles;
import org.onap.policy.rest.jpa.PolicyVersion;
-import org.onap.policy.rest.jpa.SystemLogDB;
+import org.onap.policy.rest.jpa.SystemLogDb;
import org.onap.policy.rest.jpa.UserInfo;
import org.onap.policy.rest.jpa.WatchPolicyNotificationTable;
import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
/**
* Set up all unit tests.
+ *
* @throws SQLException on SQL exceptions
*/
@BeforeClass
PolicyValidationDaoImpl.setSessionfactory(sessionFactory);
// PolicyController.setLogTableLimit("1");
// HibernateSession.setSession(sessionFactory);
- SystemLogDB data1 = new SystemLogDB();
+ SystemLogDb data1 = new SystemLogDb();
data1.setDate(new Date());
data1.setLogtype("INFO");
data1.setRemote("Test");
data1.setSystem("Test");
data1.setType("Test");
- SystemLogDB data2 = new SystemLogDB();
+ SystemLogDb data2 = new SystemLogDb();
data2.setDate(new Date());
data2.setLogtype("error");
data2.setRemote("Test");
userinfo.setUserName("Test");
commonClassDao.save(userinfo);
OnapName onapName = new OnapName();
- onapName.setOnapName("Test");
+ onapName.setName("Test");
onapName.setUserCreatedBy(userinfo);
onapName.setUserModifiedBy(userinfo);
onapName.setModifiedDate(new Date());
commonClassDao.save(onapName);
-
List<Object> list = commonClassDao.getData(OnapName.class);
assertTrue(list.size() == 1);
logger.debug(list.size());
userinfo.setUserName(loginIdUserName);
commonClassDao.save(userinfo);
-
List<Object> dataCur = commonClassDao.getDataByQuery("from UserInfo", new SimpleBindings());
assertEquals(1, dataCur.size());
params.put("scope", scope);
List<Object> dataCur = commonClassDao.getDataByQuery(query, params);
-
assertTrue(1 == dataCur.size());
assertEquals(pv, dataCur.get(0));
}
userinfo.setUserName(loginIdUserName);
commonClassDao.save(userinfo);
-
List<Object> dataCur = commonClassDao.getDataByQuery("from UserInfo", new SimpleBindings());
assertEquals(1, dataCur.size());
assertFalse(dataCur.isEmpty());
-
watch.setPolicyName("bananaWatch");
commonClassDao.save(watch);
assertEquals(watch, dataCur.get(0));
}
-
@Test
@Transactional
@Rollback(true)
watch.setPolicyName(finalName);
commonClassDao.save(watch);
-
// Current Implementation
String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId";
SimpleBindings params = new SimpleBindings();
assertTrue(dataCur.size() == 1);
assertTrue(dataCur.get(0) instanceof WatchPolicyNotificationTable);
assertEquals(watch, dataCur.get(0));
+
+ WatchPolicyNotificationTable table0 = new WatchPolicyNotificationTable();
+ WatchPolicyNotificationTable table1 = new WatchPolicyNotificationTable();
+ assertEquals(table0, table0);
+ assertEquals(table0, table1);
+ assertNotEquals(table0, null);
+ String helloString = "Hello";
+ Object helloObject = helloString;
+ assertNotEquals(table0, helloObject);
+
+ table0.setId(1);
+ assertNotEquals(table0, table1);
+ table1.setId(1);
+ assertEquals(table0, table1);
+
+ table0.setPolicyName("GoToOz");
+ assertNotEquals(table0, table1);
+ table1.setPolicyName("GoToOz");
+ assertEquals(table0, table1);
+ table1.setPolicyName(null);
+ assertNotEquals(table0, table1);
+ table0.setPolicyName(null);
+ assertEquals(table0, table1);
+ table1.setPolicyName("GoToOz");
+ assertNotEquals(table0, table1);
+ table0.setPolicyName("GoToOz");
+ assertEquals(table0, table1);
+ assertEquals(table0, table1);
+ table1.setPolicyName("InOz");
+ assertNotEquals(table0, table1);
+ table0.setPolicyName("InOz");
+ assertEquals(table0, table1);
+
+ table0.setLoginIds("Wizard");
+ assertNotEquals(table0, table1);
+ table1.setLoginIds("Wizard");
+ assertEquals(table0, table1);
+ table1.setLoginIds(null);
+ assertNotEquals(table0, table1);
+ table0.setLoginIds(null);
+ assertEquals(table0, table1);
+ table0.setLoginIds("Wizard");
+ assertNotEquals(table0, table1);
+ table1.setLoginIds("Wizard");
+ assertEquals(table0, table1);
+ table1.setLoginIds(null);
+ table1.setLoginIds("Witch");
+ assertNotEquals(table0, table1);
+ table0.setLoginIds("Witch");
+ assertEquals(table0, table1);
+
+ assertNotNull(table0.hashCode());
+ assertNotNull(table1.hashCode());
+ assertEquals(table0.hashCode(), table0.hashCode());
+
+ table0.setLoginIds("Witci");
+ assertNotEquals(table0, table1);
+ assertNotEquals(table0.hashCode(), table1.hashCode());
}
/*
// SQL Injection attempt
String finalName = "banana' OR '1'='1";
-
// Current Implementation
String query = "from WatchPolicyNotificationTable where POLICYNAME = :finalName and LOGINIDS = :userId";
SimpleBindings params = new SimpleBindings();
commonClassDao.update(userInfoUpdate);
List<String> data1 = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId");
assertTrue(data1.size() == 1);
- UserInfo data2 =
- (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", "TestID:Test1");
+ UserInfo data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName",
+ "TestID:Test1");
assertTrue("TestID".equals(data2.getUserLoginId()));
List<Object> data3 = commonClassDao.checkDuplicateEntry("TestID:Test1", "userLoginId:userName", UserInfo.class);
assertTrue(data3.size() == 1);
assertTrue(roles1.size() == 1);
List<String> multipleData = new ArrayList<>();
multipleData.add("TestID:Test1");
- List<Object> data4 =
- commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", multipleData);
+ List<Object> data4 = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName",
+ multipleData);
assertTrue(data4.size() == 1);
commonClassDao.delete(data2);
}
data = commonClassDao.getDataById(UserInfo.class, "userLoginIduserName", "TestIDTest");
assertNull(data);
data = commonClassDao.getDataById(UserInfo.class, "userLoginId data2.getUserLoginId()" + ":userName",
- "TestIDTest");
+ "TestIDTest");
assertNull(data);
commonClassDao.delete(data);
}
UserInfo userInfo = new UserInfo();
userInfo.setUserLoginId("TestID");
userInfo.setUserName("Test");
+ assertEquals("Test", userInfo.getIdentiferByUserId().getUri().getPath());
commonClassDao.save(userInfo);
List<String> multipleData = new ArrayList<>();
multipleData.add("TestID:Test1");
- List<Object> data =
- commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName", multipleData);
+ List<Object> data = commonClassDao.getMultipleDataOnAddingConjunction(UserInfo.class, "userLoginId:userName",
+ multipleData);
assertTrue(data.size() == 0);
data = commonClassDao.getMultipleDataOnAddingConjunction(null, null, null);
assertNull(data);
commonClassDao.delete(data);
}
-
@Test
public void testGetEntityItemParameters() {
UserInfo userInfo = new UserInfo();
commonClassDao.update(userInfoUpdate);
List<String> data1 = commonClassDao.getDataByColumn(UserInfo.class, "userLoginId");
assertTrue(data1.size() == 1);
- UserInfo data2 =
- (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName", "TestID:Test1");
+ UserInfo data2 = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId:userName",
+ "TestID:Test1");
assertTrue("TestID".equals(data2.getUserLoginId()));
data2 = (UserInfo) commonClassDao.getEntityItem(null, null, null);
assertNull(data2);
commonClassDao.delete(data);
}
-
@Test
public void testGetDataByQueryParameters() {
// Add data