Changeset 4000


Ignore:
Timestamp:
11/11/13 15:59:29 (11 years ago)
Author:
olhsha
Message:

the earlier fix for unit tests without setters (but using auotwired) did not work because UriInfo? cannot be presented as a bean, since it is an interface. Stters are back however the overall structure of the testing methods is not cumbersome as it was before friday.

Location:
DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src
Files:
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/main/java/eu/dasish/annotation/backend/rest/AnnotationResource.java

    r3974 r4000  
    6868    @Autowired
    6969    private DBIntegrityService dbIntegrityService;
    70     @Autowired
     70   
    7171    @Context
    7272    private HttpServletRequest httpServletRequest;
     
    7474    @Context
    7575    private HttpServletResponse httpServletResponse;
    76     @Autowired
     76   
    7777    @Context
    7878    private UriInfo uriInfo;
    79     @Autowired
     79   
    8080    @Context
    81     protected Providers providers;
     81    private Providers providers;
    8282   
    8383    final String default_permission = "reader";
    84 
     84   
     85   
     86    public void setUriInfo(UriInfo uriInfo){
     87        this.uriInfo = uriInfo;
     88    }
     89   
     90     public void setHttpServletResponse(HttpServletResponse httpServletResponse){
     91        this.httpServletResponse = httpServletResponse;
     92    }
     93     
     94    public void setHttpServletRequest(HttpServletRequest httpServletRequest){
     95        this.httpServletRequest = httpServletRequest;
     96    }
     97     
     98    public void setProviders(Providers providers){
     99        this.providers = providers;
     100    }
     101   
     102   
    85103
    86104    public AnnotationResource() {
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/AnnotationResourceTest.java

    r3974 r4000  
    5050import java.util.UUID;
    5151import javax.servlet.ServletException;
    52 import javax.servlet.http.HttpServletRequest;
    53 import javax.servlet.http.HttpServletResponse;
    54 import javax.ws.rs.core.MediaType;
    5552import javax.ws.rs.core.UriInfo;
    56 import javax.ws.rs.ext.Providers;
    5753import javax.xml.bind.JAXBException;
    58 import javax.xml.bind.Marshaller;
    5954import javax.xml.datatype.DatatypeConfigurationException;
     55import org.springframework.mock.web.MockHttpServletRequest;
    6056
    6157/**
     
    6662@RunWith(value = SpringJUnit4ClassRunner.class)
    6763@ContextConfiguration(locations = { "/spring-test-config/mockeryRest.xml", "/spring-test-config/mockDBIntegrityService.xml",
    68     "/spring-config/jaxbMarshallerFactory.xml", "/spring-test-config/mockUriInfo.xml", "/spring-test-config/mockHttpServletRequest.xml", "/spring-test-config/mockProviders.xml"})
     64    "/spring-test-config/mockUriInfo.xml",
     65    "/spring-config/jaxbMarshallerFactory.xml"})
    6966public class AnnotationResourceTest {
    7067   
    7168    @Autowired
    72     private Mockery mockeryRest;
     69    private Mockery mockeryRest;     
     70    @Autowired
     71    private MockObjectsFactoryRest mockObjectFactory;
    7372    @Autowired
    7473    private DBIntegrityService mockDbIntegrityService;
    7574    @Autowired
    76     private UriInfo mockUriInfo;
    77     @Autowired
    78     private HttpServletRequest mockHttpServletRequest;
    79    
    80     @Autowired
    81     private Providers mockProviders;   
    82     @Autowired
    8375    private AnnotationResource annotationResource;
    84    
     76    @Autowired
     77    UriInfo mockUriInfo;
     78   
     79    private MockHttpServletRequest mockRequest;
    8580   
    8681    public AnnotationResourceTest() {
    87     }
    88    
     82        mockRequest = new MockHttpServletRequest();
     83        mockRequest.setRemoteUser("twan");
     84       
     85    }
     86       
    8987   
    9088    /**
     
    9593        System.out.println("getAnnotation");
    9694        final String externalIDstring= TestBackendConstants._TEST_ANNOT_2_EXT;
    97         final Annotation expectedAnnotation = (new TestInstances()).getAnnotationOne();
    98         final ResourceJaxbMarshallerProvider rmp = new ResourceJaxbMarshallerProvider();
    99      
     95        final Annotation expectedAnnotation = (new TestInstances()).getAnnotationOne();       
     96        annotationResource.setHttpServletRequest(mockRequest);       
     97        annotationResource.setUriInfo(mockUriInfo);       
     98       
     99     
    100100        mockeryRest.checking(new Expectations() {
    101101            {
    102102               
    103                 oneOf(mockUriInfo).getBaseUri();
    104                 will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/")));
    105                
    106                  
    107                 oneOf(mockProviders).getContextResolver(Marshaller.class, MediaType.WILDCARD_TYPE);
    108                 will(returnValue(rmp));
    109                
    110                 oneOf(mockHttpServletRequest).getRemoteUser();
    111                 will(returnValue("twan"));
    112                
     103               oneOf(mockUriInfo).getBaseUri();
     104               will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/")));
     105               
     106               
    113107                oneOf(mockDbIntegrityService).setServiceURI(with(any(String.class)));
    114108                will(doAll());
     
    128122        });
    129123       
    130 
     124       
    131125        JAXBElement<Annotation> result = annotationResource.getAnnotation(externalIDstring);
    132126        assertEquals(expectedAnnotation, result.getValue());
     
    139133    public void testDeleteAnnotation() throws SQLException, IOException {
    140134        System.out.println("deleteAnnotation");
    141         //final Number annotationID = mockDbIntegrityService.getAnnotationInternalIdentifier(UUID.fromString(UUID));
    142         //int[] resultDelete = mockDbIntegrityService.deleteAnnotation(annotationID);
    143135       
    144136        final int[] mockDelete = new int[4];
     
    148140        mockDelete[3]=1; // # deletd Targets, 4
    149141       
    150        
    151      
     142        annotationResource.setHttpServletRequest(mockRequest);
     143        annotationResource.setUriInfo(mockUriInfo); 
     144       
    152145        mockeryRest.checking(new Expectations() {
    153146            { 
    154                  
    155                 oneOf(mockUriInfo).getBaseUri();
    156                 will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/")));
    157                    
    158                      
    159                 oneOf(mockHttpServletRequest).getRemoteUser();
    160                 will(returnValue("twan"));
    161                
     147               oneOf(mockUriInfo).getBaseUri();
     148               will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/")));
     149               
     150             
    162151                oneOf(mockDbIntegrityService).getUserInternalIDFromRemoteID("twan");
    163152                will(returnValue(3));
     
    219208        addedAnnotation.setOwnerRef("http://localhost:8080/annotator-backend/api/users/"+TestBackendConstants._TEST_USER_3_EXT_ID);
    220209     
     210        annotationResource.setHttpServletRequest(mockRequest);
     211        annotationResource.setUriInfo(mockUriInfo);
    221212       
    222213        mockeryRest.checking(new Expectations() {
    223214            {
    224                
    225215                oneOf(mockUriInfo).getBaseUri();
    226                 will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/")));
    227                    
    228                    
    229                 oneOf(mockHttpServletRequest).getRemoteUser();
    230                 will(returnValue("twan"));
    231                
     216                will(returnValue(URI.create("http://localhost:8080/annotator-backend/api/")));
     217               
    232218               
    233219                oneOf(mockDbIntegrityService).setServiceURI(with(any(String.class)));
  • DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/NotebookResourceTest.java

    r3974 r4000  
    3232@RunWith(value = SpringJUnit4ClassRunner.class)
    3333@ContextConfiguration(locations = {"/spring-test-config/mockeryRest.xml", "/spring-test-config/mockDBIntegrityService.xml", "/spring-config/jaxbMarshallerFactory.xml",
    34     "/spring-test-config/mockUriInfo.xml",  "/spring-test-config/mockHttpServletRequest.xml",
    35 "/spring-test-config/mockProviders.xml"})
     34    "/spring-test-config/mockUriInfo.xml"})
    3635public class NotebookResourceTest {
    3736
Note: See TracChangeset for help on using the changeset viewer.