public void setUp() { index = 0; EventDispatcher eventDispatcher = new RunnableEventDispatcher(); syncManager = new MockSyncManager(eventDispatcher, 20); settingsStore = new MockKeyValueStore(); contactsStore = new MockDataStore(); contentSinkAndSource = new MockSinkAndSource(20); protocol = new MockCommunicationManager( 20, new byte[] {ServiceObject.ACTIVITY}, new int[] {ServerRequest.GET}, new int[] {ServerRequest.ACTIVITIES}); emailProtocol = new MockEmailCommunicationManager(); context = new MockMIDlet( settingsStore, contactsStore, new MockDataStore(), new MockDataStore(), syncManager, contentSinkAndSource, contentSinkAndSource, protocol, emailProtocol, eventDispatcher, 20); model = context.getModel(); model.attach(this); }
/* public void testReceiveUpdatedLifeDrive() throws Exception { setUpAndStart(); protocol.resetEvents(); // receive push (necessary, because client doesn't request life drive at start up anymore) protocol.mockPushReceived(new APIEvent(APIEvent.TIMELINE_CHANGE)); // activities requested Assert.assertEquals("Protocol", new Event[] { new Event(Event.Context.TEST, MockCommunicationManager.SEND_REQUEST, ServerRequest.GET + ":" + ServerRequest.ACTIVITIES) }, protocol.getEvents()); // request timed out protocol.mockErrorReceived(ResponseListener.REQUEST_TIMED_OUT, ServiceObject.ACTIVITY); Assert.assertEquals("Protocol", new Event[] { new Event(Event.Context.TEST, MockCommunicationManager.SEND_REQUEST, ServerRequest.GET + ":" + ServerRequest.ACTIVITIES), new Event(Event.Context.TEST, MockCommunicationManager.SEND_REQUEST, ServerRequest.GET + ":" + ServerRequest.ACTIVITIES) }, protocol.getEvents()); // receive activities ServiceObject[] serviceObjects = new ServiceObject[4]; { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("timeline"); Hashtable contact = new Hashtable(); contact.put("contactid", new Long(70001)); Vector contactList = new Vector(); contactList.addElement(contact); ht.put("activityid", new Long(301)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "Cup of tea"); ht.put("description", "Having a nice cuppa."); ht.put("time", new Long(123456)); ht.put("contactlist", contactList); serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("timeline"); ht.put("activityid", new Long(302)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "Feet"); ht.put("description", "Putting my feet up."); ht.put("time", new Long(1234)); serviceObjects[1] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("timeline"); ht.put("activityid", new Long(303)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "Pipe"); ht.put("description", "Lighting a pipe."); ht.put("time", new Long(12345)); serviceObjects[2] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("timeline"); ht.put("activityid", new Long(304)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "No description"); ht.put("description", " "); ht.put("time", new Long(123456)); serviceObjects[3] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY); // display life drive Assert.assertEquals("Listener", new Event[] { new Event(Event.Context.APP, Event.App.START, null), new Event(Event.Context.CONTACTS, Event.Contacts.REFRESH_LIST, null), new Event(Event.Context.APP, Event.App.READY, null), new Event(Event.Context.ACTIVITY, Event.Activities.LIFE_DRIVE_CHANGED, new Integer(3)), }, getEvents()); ListSelection ls = model.getLifeDrive(0, 20); Assert.assertEquals(3, ls.getTotal()); { Activity activity = (Activity) ls.getEntries()[0]; Assert.assertEquals(301, activity.getId()); Assert.assertEquals(Activity.TYPE_CONTACT_RECEIVED_STATUS_UPDATE, activity.getType()); Assert.assertEquals(model.getContacts(null, 20).getEntries(), activity.getInvolvedContacts()); Assert.assertEquals("Cup of tea", activity.getTitle()); Assert.assertEquals("Having a nice cuppa.", activity.getDescription()); Assert.assertEquals(123456000, activity.getTime()); } { Activity activity = (Activity) ls.getEntries()[1]; Assert.assertEquals(303, activity.getId()); } { Activity activity = (Activity) ls.getEntries()[2]; Assert.assertEquals(302, activity.getId()); } Assert.assertEquals(0, model.getFriendsStream(0, 20).getTotal()); model.exit(false); } */ public void tearDown() { model.detach(this); settingsStore = null; contactsStore = null; syncManager = null; contentSinkAndSource = null; protocol = null; emailProtocol = null; context = null; model = null; }
/* public void testReceiveActivities() throws Exception { setUpAndStart(); protocol.resetEvents(); // request timed out protocol.mockErrorReceived(ResponseListener.REQUEST_TIMED_OUT, ServiceObject.ACTIVITY); Assert.assertEquals("Protocol", new Event[] { new Event(Event.Context.TEST, MockCommunicationManager.SEND_REQUEST, ServerRequest.GET + ":" + ServerRequest.ACTIVITIES) }, protocol.getEvents()); // receive activities ServiceObject[] serviceObjects = new ServiceObject[3]; { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("status"); Hashtable moreinfo = new Hashtable(); moreinfo.put("network", "facebook"); ht.put("activityid", new Long(301)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "Cup of tea"); ht.put("description", "Having a nice cuppa."); ht.put("time", new Long(123456)); //ht.put("store", "facebook"); ht.put("moreinfo", moreinfo); serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("timeline"); ht.put("activityid", new Long(302)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "Feet"); ht.put("description", "Putting my feet up."); ht.put("time", new Long(1234)); serviceObjects[1] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("timeline"); flags.addElement("status"); ht.put("activityid", new Long(303)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "Pipe"); ht.put("description", "Lighting a pipe."); ht.put("time", new Long(12345)); serviceObjects[2] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY); // display friends stream Assert.assertEquals("Listener", new Event[] { new Event(Event.Context.APP, Event.App.START, null), new Event(Event.Context.CONTACTS, Event.Contacts.REFRESH_LIST, null), new Event(Event.Context.APP, Event.App.READY, null), new Event(Event.Context.ACTIVITY, Event.Activities.LIFE_DRIVE_CHANGED, new Integer(2)), new Event(Event.Context.ACTIVITY, Event.Activities.FRIENDS_STREAM_CHANGED, new Integer(2)) }, getEvents()); ListSelection ls = model.getFriendsStream(0, 20); { Activity activity = (Activity) ls.getEntries()[0]; Assert.assertEquals(301, activity.getId()); Assert.assertEquals(Activity.TYPE_CONTACT_RECEIVED_STATUS_UPDATE, activity.getType()); Assert.assertEquals(EXTERNAL_NETWORKS[1], activity.getSource()); Assert.assertEquals("Cup of tea", activity.getTitle()); Assert.assertEquals("Having a nice cuppa.", activity.getDescription()); Assert.assertEquals(123456000, activity.getTime()); } { Activity activity = (Activity) ls.getEntries()[1]; Assert.assertEquals(303, activity.getId()); } Assert.assertEquals(2, model.getLifeDrive(0, 20).getTotal()); // receive response to first request serviceObjects = new ServiceObject[1]; { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("status"); ht.put("activityid", new Long(304)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "Hello"); ht.put("description", "Don't ignore me!"); ht.put("time", new Long(123)); serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY); Assert.assertEquals("Listener", new Event[] { new Event(Event.Context.APP, Event.App.START, null), new Event(Event.Context.CONTACTS, Event.Contacts.REFRESH_LIST, null), new Event(Event.Context.APP, Event.App.READY, null), new Event(Event.Context.ACTIVITY, Event.Activities.LIFE_DRIVE_CHANGED, new Integer(2)), new Event(Event.Context.ACTIVITY, Event.Activities.FRIENDS_STREAM_CHANGED, new Integer(2)) }, getEvents()); Assert.assertEquals(2, model.getLifeDrive(0, 20).getTotal()); Assert.assertEquals(2, model.getFriendsStream(0, 20).getTotal()); model.exit(false); } */ public void testReceiveMoreThan50Activities() throws Exception { setUpAndStart(); // receive activities ServiceObject[] serviceObjects = new ServiceObject[71]; for (int i = 0; i < serviceObjects.length; i++) { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("status"); ht.put("activityid", new Long(i)); ht.put("flaglist", flags); ht.put("type", TYPES[i]); ht.put("title", "Title"); ht.put("description", "Description"); ht.put("time", new Long(i)); serviceObjects[i] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY); // only 50 most recent are returned (message_email_received is discarded) ListSelection ls = model.getFriendsStream(0, 60); Assert.assertEquals(50, ls.getTotal()); { Activity activity = (Activity) ls.getEntries()[0]; Assert.assertEquals(70, activity.getId()); } { Activity activity = (Activity) ls.getEntries()[49]; Assert.assertEquals(20, activity.getId()); } model.exit(false); }
public void testReceiveUpdatedFriendStream() throws Exception { setUpAndStart(); protocol.resetEvents(); // receive activities ServiceObject[] serviceObjects = new ServiceObject[2]; { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("status"); ht.put("activityid", new Long(301)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "1"); ht.put("description", "No Change."); ht.put("time", new Long(12003)); serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("status"); ht.put("activityid", new Long(302)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "2a"); ht.put("description", "Before change."); ht.put("time", new Long(12002)); serviceObjects[1] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY); // receive notification protocol.mockPushReceived(new APIEvent(APIEvent.STATUS_CHANGE)); Assert.assertEquals( "Protocol", new Event[] { new Event( Event.Context.TEST, MockCommunicationManager.SEND_REQUEST, ServerRequest.GET + ":" + ServerRequest.ACTIVITIES) }, protocol.getEvents()); // receive new and updated activities serviceObjects = new ServiceObject[2]; { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("status"); ht.put("activityid", new Long(302)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "2b"); ht.put("description", "After change."); ht.put("time", new Long(12002)); serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } { Hashtable ht = new Hashtable(); Vector flags = new Vector(); flags.addElement("status"); ht.put("activityid", new Long(303)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "3"); ht.put("description", "Added."); ht.put("time", new Long(12001)); serviceObjects[1] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY); // display life drive Assert.assertEquals( "Listener", new Event[] { new Event(Event.Context.APP, Event.App.START, null), new Event(Event.Context.CONTACTS, Event.Contacts.REFRESH_LIST, null), new Event(Event.Context.APP, Event.App.READY, null), new Event(Event.Context.CHAT, Event.Chat.READY_FOR_INCOMING_MESSAGES, null), new Event(Event.Context.ACTIVITY, Event.Activities.STATUS_STREAM_CHANGED, null), new Event(Event.Context.ACTIVITY, Event.Activities.STATUS_STREAM_CHANGED, null) }, getEvents()); ListSelection ls = model.getFriendsStream(0, 20); { Activity activity = (Activity) ls.getEntries()[0]; Assert.assertEquals(301, activity.getId()); } { Activity activity = (Activity) ls.getEntries()[1]; Assert.assertEquals(302, activity.getId()); Assert.assertEquals("2b", activity.getTitle()); Assert.assertEquals("After change.", activity.getDescription()); } { Activity activity = (Activity) ls.getEntries()[2]; Assert.assertEquals(303, activity.getId()); } model.exit(false); }
public void testReceiveActivitiesWithUnknownContacts() throws Exception { setUpAndStart(); protocol.resetEvents(); // receive activities ServiceObject[] serviceObjects = new ServiceObject[2]; { Vector flags = new Vector(); flags.addElement("status"); Hashtable contact = new Hashtable(); contact.put("contactid", new Long(70001)); Vector contactList = new Vector(); contactList.addElement(contact); Hashtable ht = new Hashtable(); ht.put("activityid", new Long(301)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "Hi!"); ht.put("description", "You know me"); ht.put("time", new Long(123456)); ht.put("contactlist", contactList); serviceObjects[0] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } { Vector flags = new Vector(); flags.addElement("status"); Hashtable contact = new Hashtable(); contact.put("contactid", new Long(70002)); Vector contactList = new Vector(); contactList.addElement(contact); Hashtable ht = new Hashtable(); ht.put("activityid", new Long(302)); ht.put("flaglist", flags); ht.put("type", "contact_received_status_update"); ht.put("title", "Hi!"); ht.put("description", "You don't know me"); ht.put("time", new Long(123456)); ht.put("contactlist", contactList); serviceObjects[1] = new com.zyb.nowplus.data.protocol.types.Activity(ht); } protocol.mockItemsReceived(serviceObjects, ServiceObject.ACTIVITY); // only one is displayed ListSelection ls = model.getFriendsStream(0, 60); Assert.assertEquals(1, ls.getTotal()); { Activity activity = (Activity) ls.getEntries()[0]; Assert.assertEquals(301, activity.getId()); } // receive new contacts Vector detailList = new Vector(); { Hashtable ht = new Hashtable(); ht.put("key", "vcard.nickname"); ht.put("val", "lazy.friend"); detailList.addElement(ht); } { Hashtable ht = new Hashtable(); ht.put("key", "vcard.name"); ht.put("val", "Friend;Lazy;"); detailList.addElement(ht); } Hashtable ht = new Hashtable(); ht.put("contactid", new Long(70002)); ht.put("detaillist", detailList); ContactChanges serviceObject = new ContactChanges(ht); serviceObject.setCurrentServerRevision(34); protocol.mockItemsReceived( 1, new ServiceObject[] {serviceObject}, ServiceObject.CONTACT_CHANGES); // check activities are requested again Assert.assertEquals( "Protocol", new Event[] { new Event( Event.Context.TEST, MockCommunicationManager.SEND_REQUEST, ServerRequest.GET + ":" + ServerRequest.ACTIVITIES) }, protocol.getEvents()); model.exit(false); }
private void initForm(boolean firstLogin) { // #if !polish.blackberry this.addCommand(cmdSave); if (firstLogin) this.addCommand(cmdCancel); else this.addCommand(cmdExit); // #endif StringItem headLine; // #if polish.blackberry // #if polish.blackberry.isTouchBuild == false // #style .login_headline headLine = new StringItem(null, Locale.get("nowplus.client.java.loginform.headline")); this.append(headLine); // #endif // #else // #style .login_headline headLine = new StringItem(null, Locale.get("nowplus.client.java.loginform.headline")); this.append(headLine); // #endif // #if polish.blackberry && polish.blackberry.isTouchBuild == false headLine.setAppearanceMode(Item.PLAIN); // #endif String usernameString = model.getUserName(); String passwordString = ""; // #if username:defined // #message Username is set // #= usernameString = "${username}"; // #endif // #if password:defined // #message Password is set // #= passwordString = "${password}"; // #endif if (usernameString == null) usernameString = ""; if (passwordString == null) passwordString = ""; // username textfield // #if polish.blackberry userName = UiFactory.createTextField( Locale.get("nowplus.client.java.loginform.username.hint"), usernameString, 255, TextField.NON_PREDICTIVE, this); // fix for PBLA-816 Touch device: predictive text while disabling the surepress userName.setNoComplexInput(true); // #else userName = UiFactory.createTextField(null, usernameString, 255, TextField.NON_PREDICTIVE, this); // #endif UiAccess.setTextfieldHelp(userName, Locale.get("nowplus.client.java.loginform.username.hint")); // #if using.native.textfield:defined userName.setTitle(Locale.get("nowplus.client.java.loginform.username.hint")); // #if (${lowercase(polish.vendor)}==samsung) UiFactory.fixSamsungNativeTextField(userName); // #endif // #endif if (userName.getText().length() > 0) { // Change username textfield into uneditable field once authenticated once to keep users from // switching username userName.setConstraints(TextField.NON_PREDICTIVE | TextField.UNEDITABLE); usernameReadonly = true; // #if not polish.blackberry // #style .login_textfield_readonly // #= userName.setStyle(); // #endif } // password textfield // #if polish.blackberry passWord = UiFactory.createTextField( Locale.get("nowplus.client.java.loginform.password.hint"), passwordString, 255, TextField.NON_PREDICTIVE | TextField.INITIAL_CAPS_NEVER | TextField.PASSWORD, this); // #else passWord = UiFactory.createTextField( null, passwordString, 255, TextField.INITIAL_CAPS_NEVER | TextField.PASSWORD, this); // #endif UiAccess.setTextfieldHelp(passWord, Locale.get("nowplus.client.java.loginform.password.hint")); // #if using.native.textfield:defined passWord.setTitle(Locale.get("nowplus.client.java.loginform.password.hint")); // #if (${lowercase(polish.vendor)}==samsung) UiFactory.fixSamsungNativeTextField(passWord); // #elif polish.device.textField.requires.initialCapsNeverFix:defined UiFactory.fixS40NativeTextField(passWord); // #endif // #endif rememberMeItem = UiFactory.createChoiceCheckBoxItem( Locale.get("nowplus.client.java.loginform.rememberme.label"), Choice.MULTIPLE); rememberMeItem.select(model.stayLoggedIn()); UiFactory.createChoiceGroup( null, ChoiceGroup.MULTIPLE, new ChoiceItem[] {rememberMeItem}, 0, rememberMeItem.isSelected, null, this); // #if !polish.blackberry if (usernameReadonly) { this.focus(passWord); } // #endif // #if polish.blackberry // #style ui_factory_button_item StringItem loginButton = UiFactory.createButtonItem( null, cmdSave.getLabel(), (de.enough.polish.ui.Command) cmdSave, null, null); append(loginButton); if (firstLogin) { cmdQuit = cmdCancel; } else { cmdQuit = cmdExit; } // #endif }