Skip to content

Commit

Permalink
New Activities and BSS unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markewallace committed Sep 22, 2014
1 parent 1412842 commit 8461a99
Show file tree
Hide file tree
Showing 26 changed files with 1,806 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@
import org.junit.Test;
import org.junit.experimental.categories.Categories.ExcludeCategory;

import com.ibm.commons.util.StringUtil;
import com.ibm.commons.xml.XMLException;
import com.ibm.sbt.services.client.ClientServicesException;
import com.ibm.sbt.services.client.base.datahandlers.EntityList;
import com.ibm.sbt.services.client.connections.common.Member;
import com.ibm.sbt.test.lib.TestEnvironment;

/**
* @author mwallace
Expand All @@ -51,16 +54,35 @@ public void testGetActivitiesByTag() throws ClientServicesException, XMLExceptio
tags.add("ibmsbt");


Activity activity = createActivity(createActivityTitle(), tags);
Activity activity = createActivity(createActivityTitle(), tags, true);

this.activity = null;

//String orgid = TestEnvironment.getProperty("customerid");
//orgid = StringUtil.isEmpty(orgid) ? "*" : orgid;
//activity.addMember(Member.TYPE_ORGANIZATION, orgid, Member.ROLE_READER);
String userid = System.getProperty("UserIdAlt");
activity.addMember(Member.TYPE_PERSON, userid, Member.ROLE_READER);

//System.out.println(activity.toXmlString());

Map<String, String> parameters = new HashMap<String, String>();
parameters.put("nodetype", "activity");
parameters.put("tag", "fethard");
parameters.put("priority", "all");
parameters.put("completed", "yes");

EntityList<Activity> activities = activityService.getMyActivities(parameters);

Assert.assertEquals(1, activities.size());
Assert.assertTrue(activities.size() > 0);
Assert.assertEquals(activity.getActivityUuid(), activities.get(0).getActivityUuid());
Assert.assertEquals(2, activities.get(0).getTags().size());

ActivityService activityServiceAlt = new ActivityService(getAltEndpoint());
EntityList<Activity> activitiesAlt = activityServiceAlt.getMyActivities(parameters);
Assert.assertTrue(activitiesAlt.size()>0);
Assert.assertEquals(activity.getActivityUuid(), activitiesAlt.get(0).getActivityUuid());
Assert.assertEquals(2, activitiesAlt.get(0).getTags().size());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* © Copyright IBM Corp. 2014
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.ibm.sbt.services.client.connections.activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;

import com.ibm.commons.xml.XMLException;
import com.ibm.sbt.services.client.ClientServicesException;
import com.ibm.sbt.services.client.base.datahandlers.EntityList;

/**
* @author mwallace
*
*/
public class ActivityCreatePerformanceTest extends BaseActivityServiceTest {

@Test
public void testCreateActivityWithTags() throws ClientServicesException, XMLException {
EntityList<Activity> activities = activityService.getMyActivities();
int totalResults = activities.getTotalResults();
//System.out.println(DOMUtil.getXMLString((Node)activities.getData()));
System.out.println("Total number of activities: "+totalResults);
System.out.println("Creating "+5+" activities");
for (int i=0; i<5; i++) {
long start = System.currentTimeMillis();
Activity activity = createActivity();
long duration = System.currentTimeMillis() - start;
System.out.println("Creating "+activity.getActivityUuid()+" took "+duration+"(ms)");
}
// prevent last activity being auto-deleted
activity = null;

long start = System.currentTimeMillis();
Map<String, String> params = new HashMap<String, String>();
params.put("page", "1");
params.put("ps", "1");
params.put("nodetype", "activity");
activities = activityService.getAllActivities(params);
long duration = System.currentTimeMillis() - start;
System.out.println("Reading all activities feed took "+duration+"(ms)");

start = System.currentTimeMillis();
params.put("tag", "personal");
activities = activityService.getAllActivities(params);
duration = System.currentTimeMillis() - start;
System.out.println("Reading all activities feed (with tag=personal) took "+duration+"(ms)");

start = System.currentTimeMillis();
activities = activityService.getMyActivities(params);
duration = System.currentTimeMillis() - start;
System.out.println("Reading my activities feed (with tag=personal) took "+duration+"(ms)");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
package com.ibm.sbt.services.client.connections.activities;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;

import com.ibm.commons.xml.XMLException;
import com.ibm.sbt.services.client.ClientServicesException;
import com.ibm.sbt.services.client.base.datahandlers.EntityList;

/**
* @author mwallace
Expand All @@ -33,21 +36,44 @@ public class ActivityCreateWithTagsTest extends BaseActivityServiceTest {
@Test
public void testCreateActivityWithTags() throws ClientServicesException, XMLException {
List<String> tags = new ArrayList<String>();
tags.add("personal");
tags.add("unit_test");
tags.add("ibmsbt");
tags.add("client=46454e5f-cabe-4f00-a05a-69f15798f304");
tags.add("drafts=c20eae58-176b-40b8-9ab7-93377a906692");
tags.add("features=24010961-430e-498d-98f0-ed0b792c5bed");
tags.add("flags=ea840904-5269-4175-bbc4-e85e5eb9fafb");
tags.add("invites=a1230057-f896-423a-a0f9-cbfaa22455d2");
tags.add("muted=09bc3c51-4837-4039-96b4-c97391f87a2d");
tags.add("notification=f9229f27-60f0-41aa-9a00-532fec2c0438");
tags.add("oldsearches=dc5e13b8-e047-4e98-a274-8b2080420ad2");
tags.add("personal");
tags.add("privacy=40947664-2c2b-424f-a8c6-bad03f03ea7d");
tags.add("profile=7e30000f-f8e4-488e-8799-93f0e4bc4016");
tags.add("readmarks=1653b46c-c523-441e-b822-99b5100cf0b1");
tags.add("usages=513a38dd-edcb-4301-92f5-f8dd3822a1d0");
tags.add("user=20133257");
tags.add("user_licenses=7df630a7-7128-47ba-aeac-193097fd8c8b");

Activity activity = new Activity();
activity.setTitle(createActivityTitle());
activity.setTitle("Untitled");
activity.setTags(tags);
activity.setContent("");

Activity created = activityService.createActivity(activity);

System.out.println("CREATED: " + created.toXmlString());
//https://apps.na.collabservtest.lotus.com/activities/service/atom2/activities?nodetype=activity&page=1&priority=all&tag=user%3D20133257&ps=1&completed=yes
Map<String, String> params = new HashMap<String, String>();
params.put("nodetype", "activity");
params.put("page", "1");
params.put("priority", "all");
params.put("tag", "user=20133257");
params.put("ps", "1");
params.put("completed", "yes");
EntityList<Activity> activities = activityService.getMyActivities(params);

Assert.assertNotNull("Invalid activity id", created.getId());
Assert.assertNotNull("Invalid activity edit url", created.getEditUrl());
Assert.assertEquals("Invalid activity tags", 3, created.getTags().size());
//System.out.println("CREATED: " + created.toXmlString());

Assert.assertEquals("Invalid activity count", 1, activities.size());
Assert.assertEquals("Invalid activity id", created.getId(), activities.get(0).getId());
Assert.assertEquals("Invalid activity tags", created.getTags().size(), activities.get(0).getTags().size());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* © Copyright IBM Corp. 2014
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.ibm.sbt.services.client.connections.activities;

import java.text.MessageFormat;

import org.junit.Test;
import org.w3c.dom.Document;

import com.ibm.commons.xml.XMLException;
import com.ibm.sbt.services.client.ClientServicesException;
import com.ibm.sbt.services.client.base.ConnectionsConstants;
import com.ibm.sbt.services.client.base.datahandlers.EntityList;
import com.ibm.sbt.services.client.base.datahandlers.XmlDataHandler;
import com.ibm.sbt.services.client.connections.common.Member;

/**
* @author mwallace
*
*/
public class ActivityMemberPerformanceTest extends BaseActivityServiceTest {

@Test
public void testAddActivityMember() throws ClientServicesException, XMLException {
Activity activity = createActivity();

// e.g. ajones{0}@janet.iris.com
String emailPattern = System.getProperty("EmailPattern");

for (int i=2; i<500; i++) {
try {
long startAdd = System.currentTimeMillis();
String email = MessageFormat.format(emailPattern, i);
Member member = activity.addMember(Member.TYPE_PERSON, email, Member.ROLE_OWNER);
long durationAdd = System.currentTimeMillis() - startAdd;

long startRead = System.currentTimeMillis();
EntityList<Member> members = activity.getMembers();
XmlDataHandler dataHandler = new XmlDataHandler((Document)members.getData(), ConnectionsConstants.nameSpaceCtx);
long durationRead = System.currentTimeMillis() - startRead;

System.out.println(email+","+durationAdd+","+durationRead);
} catch (Exception ignore) {
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* © Copyright IBM Corp. 2014
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.ibm.sbt.services.client.connections.activities;

import org.junit.Assert;
import org.junit.Test;

import com.ibm.commons.xml.XMLException;
import com.ibm.sbt.services.client.ClientServicesException;
import com.ibm.sbt.services.client.base.datahandlers.EntityList;

/**
* @author mwallace
*
*/
public class ActivityMoveEntryTest extends BaseActivityServiceTest {

@Test
public void testMoveEntry() throws ClientServicesException, XMLException {
Activity activity1 = createActivity();
ActivityNode activityNode = createActivityNode();

Activity activity2 = createActivity();

activityService.moveNode(activityNode.getActivityNodeUuid(), activity2.getActivityUuid());

EntityList<ActivityNode> descendants = activityService.getActivityNodeDescendants(activity2.getActivityUuid());

Assert.assertTrue("Invalid number of descendants", descendants.size() == 1);
Assert.assertEquals("Invalid activity node id", activityNode.getActivityNodeUuid(), descendants.get(0).getActivityNodeUuid());
}


}
Loading

0 comments on commit 8461a99

Please sign in to comment.