Skip to content

Commit ede8ddc

Browse files
author
Maria Farooq
committed
finalized test
1 parent f5e6ba6 commit ede8ddc

4 files changed

Lines changed: 39 additions & 10 deletions

File tree

restcomm/restcomm.dao/src/main/java/org/restcomm/connect/dao/entities/ProfileAssociation.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ public Date getDateUpdated() {
7070
return dateUpdated;
7171
}
7272

73+
/**
74+
* @param newProfileSid
75+
* @return
76+
*/
77+
public ProfileAssociation setProfileSid(final Sid newProfileSid){
78+
return new ProfileAssociation(newProfileSid, targetSid, dateCreated, Calendar.getInstance().getTime());
79+
}
7380
@NotThreadSafe
7481
public static final class Builder {
7582
private Sid profileSid;
@@ -91,8 +98,8 @@ public void setProfileDocument(final Sid targetSid) {
9198
this.targetSid = targetSid;
9299
}
93100

94-
public void setSid(final Sid sid) {
95-
this.profileSid = sid;
101+
public void setSid(final Sid profileSid) {
102+
this.profileSid = profileSid;
96103
}
97104

98105
public void setDateCreated(final Date dateCreated) {

restcomm/restcomm.dao/src/main/java/org/restcomm/connect/dao/mybatis/MybatisProfileAssociationsDao.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ public void updateAssociatedProfileOfAllSuchProfileSid(String oldProfileSid, Str
111111
final SqlSession session = sessions.openSession();
112112
try {
113113
Map<String, Object> map = new HashMap<String, Object>();
114-
map.put("profile_sid", oldProfileSid);
115-
map.put("old_profile_sid", newProfileSid);
114+
map.put("profile_sid", newProfileSid);
115+
map.put("old_profile_sid", oldProfileSid);
116116
session.update(namespace + "updateAssociatedProfileOfAllSuchProfileSid", map);
117117
session.commit();
118118
map = null;

restcomm/restcomm.dao/src/test/java/org/restcomm/connect/dao/mybatis/ProfileAssociationsDaoTest.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void after() throws Exception {
4545
}
4646

4747
@Test
48-
public void addAndReadTest() throws IllegalArgumentException, URISyntaxException {
48+
public void profileAssociationsCRUDTest() throws IllegalArgumentException, URISyntaxException {
4949
ProfileAssociationsDao dao = manager.getProfileAssociationsDao();
5050
//TODO: update profile sid type below after merge from master
5151
Sid profileSid = Sid.generate(Sid.Type.ORGANIZATION);
@@ -64,17 +64,39 @@ public void addAndReadTest() throws IllegalArgumentException, URISyntaxException
6464
Assert.assertNotNull(resultantProfileAssociations);
6565
Assert.assertEquals(1, resultantProfileAssociations.size());
6666
Assert.assertEquals(profileAssociation.toString(), resultantProfileAssociations.get(0).toString());
67-
67+
6868
// Add another ProfileAssociation with same profile
6969
Sid targetSid2 = Sid.generate(Sid.Type.ACCOUNT);
7070
ProfileAssociation profileAssociation2 = new ProfileAssociation(profileSid, targetSid2, Calendar.getInstance().getTime(), Calendar.getInstance().getTime());
7171
dao.addProfileAssociation(profileAssociation2);
7272
resultantProfileAssociations = dao.getProfileAssociationsByProfileSid(profileSid.toString());
7373
Assert.assertNotNull(resultantProfileAssociations);
7474
Assert.assertEquals(2, resultantProfileAssociations.size());
75+
76+
//Update Associated Profile Of All Such ProfileSid
77+
//TODO: update profile sid type below after merge from master
78+
Sid newProfileSid = Sid.generate(Sid.Type.ORGANIZATION);
79+
dao.updateAssociatedProfileOfAllSuchProfileSid(profileSid.toString(), newProfileSid.toString());
80+
Assert.assertEquals(0, dao.getProfileAssociationsByProfileSid(profileSid.toString()).size());
81+
Assert.assertEquals(2, dao.getProfileAssociationsByProfileSid(newProfileSid.toString()).size());
82+
83+
//Update ProfileAssociation of target
84+
//TODO: update profile sid type below after merge from master
85+
Sid newProfileSid2 = Sid.generate(Sid.Type.ORGANIZATION);
86+
profileAssociation = dao.getProfileAssociationsByProfileSid(newProfileSid.toString()).get(0);
87+
ProfileAssociation updatedProfileAssociation = profileAssociation.setProfileSid(newProfileSid2);
88+
dao.updateProfileAssociationOfTargetSid(updatedProfileAssociation);
89+
ProfileAssociation resultantProfileAssociationdao = dao.getProfileAssociationByTargetSid(updatedProfileAssociation.getTargetSid().toString());
90+
Assert.assertNotNull(resultantProfileAssociationdao);
91+
Assert.assertEquals(updatedProfileAssociation.getProfileSid().toString(), resultantProfileAssociationdao.getProfileSid().toString());
92+
93+
//Delete ByProfileSid
94+
dao.deleteProfileAssociationByProfileSid(newProfileSid2.toString());
95+
Assert.assertEquals(0,dao.getProfileAssociationsByProfileSid(newProfileSid2.toString()).size());
7596

76-
//Update ProfileAssociation
77-
97+
//Delete ByTargetSid
98+
dao.deleteProfileAssociationByTargetSid(resultantProfileAssociationdao.getProfileSid().toString());
99+
Assert.assertNull(dao.getProfileAssociationByTargetSid(resultantProfileAssociationdao.getProfileSid().toString()));
78100
}
79101

80102
}

restcomm/restcomm.dao/src/test/resources/organizationsDao/profileassociation.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
</select>
1717

1818
<update id="updateProfileAssociationOfTargetSid" parameterType="map">
19-
UPDATE "restcomm_profile_associations" SET "date_updated"=#{date_updated},
19+
UPDATE "restcomm_profile_associations" SET "date_updated"=NOW(),
2020
"profile_sid"=#{profile_sid}
2121
WHERE "target_sid"=#{target_sid};
2222
</update>
2323

2424
<update id="updateAssociatedProfileOfAllSuchProfileSid" parameterType="map">
25-
UPDATE "restcomm_profile_associations" SET "date_updated"=#{date_updated},
25+
UPDATE "restcomm_profile_associations" SET "date_updated"=NOW(),
2626
"profile_sid"=#{profile_sid}
2727
WHERE "profile_sid"=#{old_profile_sid};
2828
</update>

0 commit comments

Comments
 (0)