Ignore:
Timestamp:
08/21/13 09:47:33 (11 years ago)
Author:
olhsha
Message:

making interface and bean for DaoDispatcher?. AnnotationResourceTest? passed with 3 methods: get, add and delete annotations. AnnotationsTest? still have problems.

File:
1 edited

Legend:

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

    r3450 r3452  
    1818package eu.dasish.annotation.backend.rest;
    1919
     20import eu.dasish.annotation.backend.dao.DaoDispatcher;
    2021import com.sun.jersey.api.client.GenericType;
     22import eu.dasish.annotation.backend.Helpers;
    2123import eu.dasish.annotation.backend.TestBackendConstants;
    2224import eu.dasish.annotation.backend.TestInstances;
     
    2426import eu.dasish.annotation.backend.identifiers.UserIdentifier;
    2527import eu.dasish.annotation.schema.Annotation;
     28import eu.dasish.annotation.schema.ResourceREF;
    2629import java.sql.SQLException;
    2730import javax.xml.bind.JAXBElement;
     
    3538import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
    3639import java.lang.InstantiationException;
     40import java.sql.Timestamp;
    3741import javax.servlet.ServletException;
     42import javax.xml.datatype.DatatypeConfigurationException;
     43import org.junit.Ignore;
    3844import org.springframework.mock.web.MockHttpServletRequest;
    3945/**
     
    4349
    4450@RunWith(value = SpringJUnit4ClassRunner.class)
    45 @ContextConfiguration(locations = {"/spring-test-config/dataSource.xml", "/spring-test-config/mockDaoDispatcher.xml",
    46     "/spring-test-config/mockery.xml", })
     51@ContextConfiguration(locations = { "/spring-test-config/mockery.xml", "/spring-test-config/mockDaoDispatcher.xml",
     52"/spring-test-config/mockAnnotationDao.xml","/spring-test-config/mockUserDao.xml", "/spring-test-config/mockNotebookDao.xml",
     53"/spring-test-config/mockSourceDao.xml", "/spring-test-config/mockVersionDao.xml", "/spring-test-config/mockCachedRepresentationDao.xml"})
    4754public class AnnotationResourceTest {
    4855   
     
    93100        //int[] resultDelete = daoDispatcher.deleteAnnotation(annotationID);
    94101       
     102        final int[] mockDelete = new int[4];
     103        mockDelete[0]=1; // # deleted annotations
     104        mockDelete[3]=1; // # deleted annotation_prinipal_permissions
     105        mockDelete[2]=2; // # deleted  annotations_target_sources, (5,3), (5,4)
     106        mockDelete[3]=1; // # deletd sources, 4
    95107        mockery.checking(new Expectations() {
    96108            { 
     
    99111               
    100112                oneOf(daoDispatcher).deleteAnnotation(5);
    101                 will(returnValue(1));
     113                will(returnValue(mockDelete));
    102114            }
    103115        });
     
    111123     */
    112124    @Test
    113     public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, ServletException {
     125    public void testCreateAnnotation() throws SQLException, InstantiationException, IllegalAccessException, ServletException, DatatypeConfigurationException {
    114126        System.out.println("test createAnnotation");
    115127        final Annotation annotationToAdd = new GenericType<Annotation>(){}.getRawClass().newInstance();
     
    121133//        Number newAnnotationID =  daoDispatcher.addUsersAnnotation(annotation, userID);
    122134//        Annotation newAnnotation = daoDispatcher.getAnnotation(newAnnotationID);
     135        final String ownerString = "5";
     136        final Number ownerID =  5;
     137        final Number newAnnotationID = 6;
     138        final Annotation addedAnnotation = annotationToAdd;
     139        ResourceREF owner = new ResourceREF();
     140        owner.setRef(ownerString);
     141        addedAnnotation.setOwner(owner);
     142        addedAnnotation.setURI((new AnnotationIdentifier()).toString());
    123143       
     144        addedAnnotation.setTimeStamp(Helpers.setXMLGregorianCalendar(Timestamp.valueOf("2013-08-12 11:25:00.383000")));
    124145        mockery.checking(new Expectations() {
    125146            {
    126147                oneOf(daoDispatcher).getUserInternalIdentifier(with(aNonNull(UserIdentifier.class)));
    127                 will(returnValue(5));
     148                will(returnValue(ownerID));
    128149               
    129                 oneOf(daoDispatcher).addUsersAnnotation(annotationToAdd, 5);
    130                 will(returnValue(1));
     150                oneOf(daoDispatcher).addUsersAnnotation(annotationToAdd, ownerID);
     151                will(returnValue(newAnnotationID));
     152               
     153                oneOf(daoDispatcher).getAnnotation(newAnnotationID);
     154                will(returnValue(addedAnnotation));
    131155            }
    132156        });
     
    139163       
    140164        JAXBElement<Annotation> result = annotationResource.createAnnotation(annotationToAdd);
    141         assertEquals(String.valueOf(5), result.getValue().getOwner().getRef());
    142         assertFalse(null == result.getValue().getURI());
     165        assertEquals(addedAnnotation.getOwner().getRef(), result.getValue().getOwner().getRef());
     166        assertEquals(addedAnnotation.getURI(), result.getValue().getURI());
     167        assertEquals(addedAnnotation.getHeadline(), result.getValue().getHeadline());
     168        assertEquals(addedAnnotation.getPermissions(), result.getValue().getPermissions());
     169        assertEquals(addedAnnotation.getTargetSources(), result.getValue().getTargetSources());
     170        assertEquals(addedAnnotation.getTimeStamp(), result.getValue().getTimeStamp());
     171        assertEquals(addedAnnotation.getBody(), result.getValue().getBody());
    143172       
    144173    }
Note: See TracChangeset for help on using the changeset viewer.