Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

Commit

Permalink
test code on form
Browse files Browse the repository at this point in the history
  • Loading branch information
Proshanto committed Jul 4, 2017
1 parent 0c40600 commit c66b17b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opensrp.form.domain;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
Expand Down Expand Up @@ -30,12 +31,14 @@ public void shouldTestEqualsAndHash(){
@Test
public void shouldTestConstructor(){
assertEquals(getForm().bindType(),"pkchild");
assertNotSame(getForm().bindType(),"pkchilds");

}

@Test
public void shouldGetSubFormByName(){
assertEquals("woman_registration", getForm().getSubFormByName("woman_registration").name());
assertNotSame("woman_registrations", getForm().getSubFormByName("woman_registration").name());

}
public FormData getForm(){
Expand Down Expand Up @@ -76,11 +79,13 @@ public void shouldGetRunTimeExceptionBygetSubFormByName(){
//sub_forms.add(subFormData);
FormData formData2 = new FormData(bind_type,default_bind_path,fields,sub_forms);
assertEquals("woman_registration", formData2.getSubFormByName("woman_registration").name());
assertNotSame("woman_registrations", formData2.getSubFormByName("woman_registration").name());

}
@Test
public void shouldGetFieldsAsMap(){
assertEquals("providerCity", getForm().getFieldsAsMap().get("provider_city"));
assertNotSame("providerCity", getForm().getFieldsAsMap().get("provider_cityu"));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ public void shouldTestCOnstructorAndGetSubFormByName(){
formInstance1.toString();
assertNotNull(formInstance1);
assertEquals("woman_registration",formInstance.getSubFormByName("woman_registration").name());
assertNotSame("woman_registrations",formInstance.getSubFormByName("woman_registration").name());

}

@Test(expected=RuntimeException.class)
public void shouldGetRuntimeExcemptionTestCOnstructorAndGetSubFormByName(){
FormDataTest formDataTest = new FormDataTest();
FormData formData = formDataTest.getForm();
FormInstance formInstance = new FormInstance(formData, "1");
FormInstance formInstance1 = new FormInstance(formData);
formInstance1.toString();
formInstance.getSubFormByName("woman_registrations").name();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.opensrp.form.domain;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -37,8 +38,9 @@ public void shouldGetSubFormByName(){
fieldNames.add("provider_town");
FormSubmission formSubmission = new FormSubmission("ANM1", "", "pkchild", "", "1", 0l, formInstance);
assertEquals("woman_registration", formSubmission.getSubFormByName("woman_registration").name());

}
assertNotSame("woman_registrationw", formSubmission.getSubFormByName("woman_registration").name());
}


@Test(expected=RuntimeException.class)
public void shouldGetRuntimeExceptionWhenGetSubFormByName() throws Exception{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public void shouldFindByFormName(){

}

@Test(expected=IndexOutOfBoundsException.class)
public void shouldGetRuntimeExceptionForFindByFormName(){
long baseTimeStamp = DateUtil.now().getMillis();
String provider = "ANM 6";
FormSubmission firstFormSubmission = new FormSubmission("ANM 6", "instance id 77", "DemoForm77", "entity id 778", 0L, "1", null, baseTimeStamp);
Map<String, Object> metadata = new HashMap<>();
metadata.put("formType", new String("type"));
firstFormSubmission.setMetadata(metadata);
formSubmissions.add(firstFormSubmission);
formSubmissionService.findByFormName("DemoForm77t", 0l).get(0).anmId();

}

@SuppressWarnings("deprecation")
@Test
public void shouldFindByInstanceId(){
Expand Down Expand Up @@ -93,7 +106,7 @@ public void shouldGetAllFormSubmissions(){
long baseTimeStamp = DateUtil.now().getMillis();
FormSubmission firstFormSubmission = new FormSubmission("ANM 1", "instance id 1", "DemoForm Name", "entity id 1", 0L, "1", null, baseTimeStamp);
formSubmissions.add(firstFormSubmission);
assertEquals("form name 1", formSubmissionService.getAllSubmissions(getStdCouchDbConnectorForOpensrpForm(),0L, 1).get(0).formName());
assertEquals(1, formSubmissionService.getAllSubmissions(getStdCouchDbConnectorForOpensrpForm(),0L, 1).size());

}

Expand Down

0 comments on commit c66b17b

Please sign in to comment.