Search in sources :

Example 1 with SyncInput

use of ca.nrc.cadc.rest.SyncInput in project caom2db by opencadc.

the class GetActionTest method testDoIt.

@Test
public void testDoIt() throws Exception {
    // test the doIt method when it returns 2 observations
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    GetAction getAction = new TestGetAction(mockDao);
    TestSyncOutput out = new TestSyncOutput();
    getAction.setSyncOutput(out);
    reset(mockDao);
    expect(mockRequest.getMethod()).andReturn("GET");
    expect(mockRequest.getServletPath()).andReturn("/obs").atLeastOnce();
    expect(mockRequest.getPathInfo()).andReturn("TEST").atLeastOnce();
    // build the list of observations for the mock dao to return
    List<ObservationState> obsList = new ArrayList<ObservationState>();
    DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
    ObservationState os1 = new ObservationState(new ObservationURI("TEST", "1234"));
    os1.maxLastModified = df.parse("2010-10-10T10:10:10.10");
    os1.accMetaChecksum = URI.create("md5:5b71d023d4729575d550536dce8439e6");
    obsList.add(os1);
    ObservationState os2 = new ObservationState(new ObservationURI("TEST", "6789"));
    os2.maxLastModified = df.parse("2011-11-11T11:11:11.111");
    os2.accMetaChecksum = URI.create("md5:aedbcf5e27a17fc2daa5a0e0d7840009");
    obsList.add(os2);
    Enumeration<String> params = Collections.emptyEnumeration();
    expect(mockRequest.getParameterNames()).andReturn(params);
    // since no maxRec argument given, expect the default one
    expect(mockDao.getObservationList("TEST", null, null, RepoAction.MAX_LIST_SIZE, true)).andReturn(obsList);
    replay(mockDao, mockRequest);
    getAction.setSyncInput(new SyncInput(mockRequest, getAction.getInlineContentHandler()));
    getAction.run();
    String expected = "TEST" + "\t" + "1234" + "\t" + df.format(os1.maxLastModified) + "\t" + os1.accMetaChecksum.toString() + "\n" + "TEST" + "\t" + "6789" + "\t" + df.format(os2.maxLastModified) + "\t" + os2.accMetaChecksum.toString() + "\n";
    String content = out.getContent();
    log.debug("\n--list content start--\n" + content + "\n--list content end--");
    Assert.assertEquals(expected, content);
    // repeat test when start, end, maxRec and ascendingOrder specified
    getAction = new TestGetAction(mockDao);
    reset(mockDao);
    reset(mockRequest);
    // get a new OutSync
    out = new TestSyncOutput();
    getAction.setSyncOutput(out);
    // build the list of observations for the mock dao to return
    expect(mockRequest.getMethod()).andReturn("GET");
    expect(mockRequest.getPathInfo()).andReturn("/TEST");
    List<String> keys = new ArrayList<String>();
    keys.add("MAXREC");
    keys.add("Start");
    keys.add("end");
    params = Collections.enumeration(keys);
    String startDate = "2010-10-10T10:10:10.1";
    String endDate = "2011-11-11T11:11:11.111";
    expect(mockRequest.getParameterNames()).andReturn(params);
    expect(mockRequest.getParameterValues("MAXREC")).andReturn(new String[] { "3" });
    expect(mockRequest.getParameterValues("Start")).andReturn(new String[] { startDate });
    expect(mockRequest.getParameterValues("end")).andReturn(new String[] { endDate });
    // all arguments given
    expect(mockDao.getObservationList("TEST", df.parse(startDate), df.parse(endDate), 3, true)).andReturn(obsList);
    replay(mockDao, mockRequest);
    getAction.setSyncInput(new SyncInput(mockRequest, getAction.getInlineContentHandler()));
    getAction.run();
    Assert.assertEquals(expected, out.getContent());
    log.info("Finished testDoIt.");
}
Also used : TestSyncOutput(ca.nrc.cadc.caom2.repo.TestSyncOutput) ObservationURI(ca.nrc.cadc.caom2.ObservationURI) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) DateFormat(java.text.DateFormat) ObservationState(ca.nrc.cadc.caom2.ObservationState) SyncInput(ca.nrc.cadc.rest.SyncInput) Test(org.junit.Test)

Example 2 with SyncInput

use of ca.nrc.cadc.rest.SyncInput in project caom2db by opencadc.

the class GetAction23Test method testCollectionNotFoundException.

@Test(expected = ResourceNotFoundException.class)
public void testCollectionNotFoundException() throws Exception {
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    reset(mockDao);
    expect(mockRequest.getMethod()).andReturn("GET");
    expect(mockRequest.getServletPath()).andReturn("/obs").atLeastOnce();
    expect(mockRequest.getPathInfo()).andReturn("BLAH").atLeastOnce();
    expect(mockDao.getObservationList("BLAH", null, null, null, true)).andReturn(null);
    Enumeration<String> params = Collections.emptyEnumeration();
    expect(mockRequest.getParameterNames()).andReturn(params);
    replay(mockDao, mockRequest);
    GetAction23 getAction = new TestGetAction(mockDao);
    getAction.setSyncInput(new SyncInput(mockRequest, getAction.getInlineContentHandler()));
    getAction.doAction();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SyncInput(ca.nrc.cadc.rest.SyncInput) Test(org.junit.Test)

Example 3 with SyncInput

use of ca.nrc.cadc.rest.SyncInput in project caom2db by opencadc.

the class GetAction23Test method testDoIt.

@Test
public void testDoIt() throws Exception {
    // test the doIt method when it returns 2 observations
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    GetAction23 getAction = new TestGetAction(mockDao);
    TestSyncOutput out = new TestSyncOutput();
    getAction.setSyncOutput(out);
    reset(mockDao);
    expect(mockRequest.getMethod()).andReturn("GET");
    expect(mockRequest.getServletPath()).andReturn("/obs").atLeastOnce();
    expect(mockRequest.getPathInfo()).andReturn("TEST").atLeastOnce();
    // build the list of observations for the mock dao to return
    List<ObservationState> obsList = new ArrayList<ObservationState>();
    DateFormat df = DateUtil.getDateFormat(DateUtil.IVOA_DATE_FORMAT, DateUtil.UTC);
    ObservationState os1 = new ObservationState(new ObservationURI("TEST", "1234"));
    os1.maxLastModified = df.parse("2010-10-10T10:10:10.10");
    os1.accMetaChecksum = URI.create("md5:5b71d023d4729575d550536dce8439e6");
    obsList.add(os1);
    ObservationState os2 = new ObservationState(new ObservationURI("TEST", "6789"));
    os2.maxLastModified = df.parse("2011-11-11T11:11:11.111");
    os2.accMetaChecksum = URI.create("md5:aedbcf5e27a17fc2daa5a0e0d7840009");
    obsList.add(os2);
    Enumeration<String> params = Collections.emptyEnumeration();
    expect(mockRequest.getParameterNames()).andReturn(params);
    // since no maxRec argument given, expect the default one
    expect(mockDao.getObservationList("TEST", null, null, RepoAction.MAX_LIST_SIZE, true)).andReturn(obsList);
    replay(mockDao, mockRequest);
    getAction.setSyncInput(new SyncInput(mockRequest, getAction.getInlineContentHandler()));
    getAction.run();
    String expected = "TEST" + "\t" + "1234" + "\t" + df.format(os1.maxLastModified) + "\t" + os1.accMetaChecksum.toString() + "\n" + "TEST" + "\t" + "6789" + "\t" + df.format(os2.maxLastModified) + "\t" + os2.accMetaChecksum.toString() + "\n";
    String content = out.getContent();
    log.debug("\n--list content start--\n" + content + "\n--list content end--");
    Assert.assertEquals(expected, content);
    // repeat test when start, end, maxRec and ascendingOrder specified
    getAction = new TestGetAction(mockDao);
    reset(mockDao);
    reset(mockRequest);
    // get a new OutSync
    out = new TestSyncOutput();
    getAction.setSyncOutput(out);
    // build the list of observations for the mock dao to return
    expect(mockRequest.getMethod()).andReturn("GET");
    expect(mockRequest.getPathInfo()).andReturn("/TEST");
    List<String> keys = new ArrayList<String>();
    keys.add("MAXREC");
    keys.add("Start");
    keys.add("end");
    params = Collections.enumeration(keys);
    String startDate = "2010-10-10T10:10:10.1";
    String endDate = "2011-11-11T11:11:11.111";
    expect(mockRequest.getParameterNames()).andReturn(params);
    expect(mockRequest.getParameterValues("MAXREC")).andReturn(new String[] { "3" });
    expect(mockRequest.getParameterValues("Start")).andReturn(new String[] { startDate });
    expect(mockRequest.getParameterValues("end")).andReturn(new String[] { endDate });
    // all arguments given
    expect(mockDao.getObservationList("TEST", df.parse(startDate), df.parse(endDate), 3, true)).andReturn(obsList);
    replay(mockDao, mockRequest);
    getAction.setSyncInput(new SyncInput(mockRequest, getAction.getInlineContentHandler()));
    getAction.run();
    Assert.assertEquals(expected, out.getContent());
    log.info("Finished testDoIt.");
}
Also used : TestSyncOutput(ca.nrc.cadc.caom2.repo.TestSyncOutput) ObservationURI(ca.nrc.cadc.caom2.ObservationURI) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) DateFormat(java.text.DateFormat) ObservationState(ca.nrc.cadc.caom2.ObservationState) SyncInput(ca.nrc.cadc.rest.SyncInput) Test(org.junit.Test)

Example 4 with SyncInput

use of ca.nrc.cadc.rest.SyncInput in project caom2db by opencadc.

the class GetActionTest method testCollectionNotFoundException.

@Test(expected = ResourceNotFoundException.class)
public void testCollectionNotFoundException() throws Exception {
    HttpServletRequest mockRequest = mock(HttpServletRequest.class);
    reset(mockDao);
    expect(mockRequest.getMethod()).andReturn("GET");
    expect(mockRequest.getServletPath()).andReturn("/obs").atLeastOnce();
    expect(mockRequest.getPathInfo()).andReturn("BLAH").atLeastOnce();
    expect(mockDao.getObservationList("BLAH", null, null, null, true)).andReturn(null);
    Enumeration<String> params = Collections.emptyEnumeration();
    expect(mockRequest.getParameterNames()).andReturn(params);
    replay(mockDao, mockRequest);
    GetAction getAction = new TestGetAction(mockDao);
    getAction.setSyncInput(new SyncInput(mockRequest, getAction.getInlineContentHandler()));
    getAction.doAction();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SyncInput(ca.nrc.cadc.rest.SyncInput) Test(org.junit.Test)

Aggregations

SyncInput (ca.nrc.cadc.rest.SyncInput)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 Test (org.junit.Test)4 ObservationState (ca.nrc.cadc.caom2.ObservationState)2 ObservationURI (ca.nrc.cadc.caom2.ObservationURI)2 TestSyncOutput (ca.nrc.cadc.caom2.repo.TestSyncOutput)2 DateFormat (java.text.DateFormat)2 ArrayList (java.util.ArrayList)2