Example usage for junit.framework Assert assertNull

List of usage examples for junit.framework Assert assertNull

Introduction

In this page you can find the example usage for junit.framework Assert assertNull.

Prototype

static public void assertNull(Object object) 

Source Link

Document

Asserts that an object is null.

Usage

From source file:org.opencastproject.scheduler.impl.SchedulerServiceImplTest.java

@Test
public void testCalendarNotModified() throws Exception {
    HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class);
    EasyMock.replay(request);//from   w  w  w  . j a  v  a2 s.  c om

    SchedulerRestService restService = new SchedulerRestService();
    restService.setService(schedSvc);
    restService.setDublinCoreService(dcSvc);

    String device = "Test Device";

    // Store an event
    final DublinCoreCatalog event = generateEvent(device, new Date(),
            new Date(System.currentTimeMillis() + 60000));
    final long eventId = schedSvc.addEvent(event, wfProperties);

    // Request the calendar without specifying an etag. We should get a 200 with the icalendar in the response body
    Response response = restService.getCalendar(device, null, null, request);
    Assert.assertNotNull(response.getEntity());
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    final String etag = (String) response.getMetadata().getFirst(HttpHeaders.ETAG);

    EasyMock.reset(request);
    EasyMock.expect(request.getHeader("If-None-Match")).andAnswer(new IAnswer<String>() {
        @Override
        public String answer() throws Throwable {
            return etag;
        }
    }).anyTimes();
    EasyMock.replay(request);

    // Request using the etag from the first response. We should get a 304 (not modified)
    response = restService.getCalendar(device, null, null, request);
    assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getStatus());
    Assert.assertNull(response.getEntity());

    // Update the event
    schedSvc.updateEvent(eventId, event, wfPropertiesUpdated);

    // Try using the same old etag. We should get a 200, since the event has changed
    response = restService.getCalendar(device, null, null, request);
    assertEquals(HttpServletResponse.SC_OK, response.getStatus());
    Assert.assertNotNull(response.getEntity());
    String secondEtag = (String) response.getMetadata().getFirst(HttpHeaders.ETAG);

    Assert.assertNotNull(secondEtag);
    Assert.assertFalse(etag.equals(secondEtag));
}

From source file:org.opencastproject.util.FileSupportTest.java

@Test
public void missingLinkTestFailsWithoutForce() {
    try {// w w  w . ja  v a 2s .c  o  m
        Assert.assertNull(FileSupport.link(linkLocation, fileToLink, false));
        Assert.fail();
    } catch (IOException e) {
        // Test should have IOException. 
    }
}

From source file:org.opencastproject.util.FileSupportTest.java

@Test
public void missingLinkTestFailsWithForce() {
    try {/*from  w  ww. ja v  a  2s .c o m*/
        Assert.assertNull(FileSupport.link(linkLocation, fileToLink, true));
        Assert.fail();
    } catch (IOException e) {
        // Test should have IOException. 
    }
}

From source file:org.opencastproject.workingfilerepository.impl.WorkingFileRepositoryRestEndpointTest.java

public void testEtag() throws Exception {
    String mediaPackageId = "mp";
    String dc = "element1";
    InputStream in = null;//from  w ww .j  av a  2s.  c  o m
    InputStream responseIn = null;
    try {
        in = getClass().getResourceAsStream("/dublincore.xml");
        endpoint.put(mediaPackageId, dc, "dublincore.xml", in);
    } finally {
        IOUtils.closeQuietly(in);
    }

    try {
        in = getClass().getResourceAsStream("/dublincore.xml");
        String md5 = DigestUtils.md5Hex(in);
        Response response = endpoint.restGet(mediaPackageId, dc, md5);
        Assert.assertEquals(Response.Status.NOT_MODIFIED.getStatusCode(), response.getStatus());
        responseIn = (InputStream) response.getEntity();
        Assert.assertNull(responseIn);
        response = endpoint.restGet(mediaPackageId, dc, "foo");
        Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
        responseIn = (InputStream) response.getEntity();
        Assert.assertNotNull(responseIn);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(responseIn);
    }

}

From source file:org.opendaylight.controller.sample.zeromq.test.it.RouterTest.java

@Test
public void testInvokeRpcWithNullInput() throws Exception {
    //Thread.sleep(1500);

    ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class);
    Assert.assertNotNull(providerRef);//ww  w .j  a v a2  s.  c  om
    ExampleProvider provider = (ExampleProvider) ctx.getService(providerRef);
    Assert.assertNotNull(provider);
    ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class);
    Assert.assertNotNull(consumerRef);
    ExampleConsumer consumer = (ExampleConsumer) ctx.getService(consumerRef);
    Assert.assertNotNull(consumer);

    // Provider sends announcement
    _logger.debug("Provider sends announcement [{}]", QNAME.getLocalName());
    provider.announce(QNAME);
    // Consumer invokes RPC
    _logger.debug("Invoking RPC [{}]", QNAME);
    for (int i = 0; i < 3; i++) {
        RpcResult<CompositeNode> result = consumer.invokeRpc(QNAME, null);
        Assert.assertNotNull(result);
        _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(),
                result.getResult(), result.getErrors());
        Assert.assertFalse(result.isSuccessful());
        Assert.assertNull(result.getResult());
        Assert.assertEquals(1, result.getErrors().size());
        Assert.assertEquals(RpcError.ErrorSeverity.WARNING,
                ((RpcError) result.getErrors().toArray()[0]).getSeverity());
    }
}

From source file:org.opendaylight.controller.sample.zeromq.test.it.RouterTest.java

@Test
public void testInvokeRpcWithInvalidSimpleNode() throws Exception {
    //Thread.sleep(1500);

    ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class);
    Assert.assertNotNull(providerRef);//from w  ww.  j a v  a 2  s  .  co  m
    ExampleProvider provider = (ExampleProvider) ctx.getService(providerRef);
    Assert.assertNotNull(provider);
    ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class);
    Assert.assertNotNull(consumerRef);
    ExampleConsumer consumer = (ExampleConsumer) ctx.getService(consumerRef);
    Assert.assertNotNull(consumer);

    // Provider sends announcement
    _logger.debug("Provider sends announcement [{}]", QNAME.getLocalName());
    provider.announce(QNAME);
    // Consumer invokes RPC
    _logger.debug("Invoking RPC [{}]", QNAME);
    CompositeNode input = consumer.getInvalidCompositeNodeSimpleChild();
    for (int i = 0; i < 3; i++) {
        RpcResult<CompositeNode> result = consumer.invokeRpc(QNAME, input);
        Assert.assertNotNull(result);
        _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(),
                result.getResult(), result.getErrors());
        Assert.assertFalse(result.isSuccessful());
        Assert.assertNull(result.getResult());
        Assert.assertEquals(1, result.getErrors().size());
        Assert.assertEquals(RpcError.ErrorSeverity.ERROR,
                ((RpcError) result.getErrors().toArray()[0]).getSeverity());
    }
}

From source file:org.opendaylight.controller.sample.zeromq.test.it.RouterTest.java

@Test
public void testInvokeRpcWithInvalidCompositeNode() throws Exception {
    //Thread.sleep(1500);

    ServiceReference providerRef = ctx.getServiceReference(ExampleProvider.class);
    Assert.assertNotNull(providerRef);//from   w w w  . ja  v  a2  s  .c o  m
    ExampleProvider provider = (ExampleProvider) ctx.getService(providerRef);
    Assert.assertNotNull(provider);
    ServiceReference consumerRef = ctx.getServiceReference(ExampleConsumer.class);
    Assert.assertNotNull(consumerRef);
    ExampleConsumer consumer = (ExampleConsumer) ctx.getService(consumerRef);
    Assert.assertNotNull(consumer);

    // Provider sends announcement
    _logger.debug("Provider sends announcement [{}]", QNAME.getLocalName());
    provider.announce(QNAME);
    // Consumer invokes RPC
    _logger.debug("Invoking RPC [{}]", QNAME);
    CompositeNode input = consumer.getInvalidCompositeNodeCompositeChild();
    for (int i = 0; i < 3; i++) {
        RpcResult<CompositeNode> result = consumer.invokeRpc(QNAME, input);
        Assert.assertNotNull(result);
        _logger.debug("{}-> Result is: Successful:[{}], Payload:[{}], Errors: [{}]", i, result.isSuccessful(),
                result.getResult(), result.getErrors());
        Assert.assertFalse(result.isSuccessful());
        Assert.assertNull(result.getResult());
        Assert.assertEquals(1, result.getErrors().size());
        Assert.assertEquals(RpcError.ErrorSeverity.ERROR,
                ((RpcError) result.getErrors().toArray()[0]).getSeverity());
    }
}

From source file:org.openmrs.api.VisitServiceTest.java

@Test
@Verifies(value = "should get correct visit type", method = "getVisitType(Integer)")
public void getVisitType_shouldGetCorrectVisitType() throws Exception {
    VisitType visitType = Context.getVisitService().getVisitType(1);
    assertNotNull(visitType);/* w  ww  . ja  v  a2  s. c om*/
    assertEquals("Initial HIV Clinic Visit", visitType.getName());

    visitType = Context.getVisitService().getVisitType(2);
    assertNotNull(visitType);
    assertEquals("Return TB Clinic Visit", visitType.getName());

    visitType = Context.getVisitService().getVisitType(3);
    assertNotNull(visitType);
    assertEquals("Hospitalization", visitType.getName());

    visitType = Context.getVisitService().getVisitType(4);
    Assert.assertNull(visitType);
}

From source file:org.openmrs.api.VisitServiceTest.java

@Test
@Verifies(value = "should get correct visit type", method = "getVisitTypeByUuid(String)")
public void getVisitTypeByUuid_shouldGetCorrentVisitType() throws Exception {
    VisitType visitType = Context.getVisitService().getVisitTypeByUuid("c0c579b0-8e59-401d-8a4a-976a0b183519");
    assertNotNull(visitType);/*w ww .  ja  v  a 2  s  .c  om*/
    assertEquals("Initial HIV Clinic Visit", visitType.getName());

    visitType = Context.getVisitService().getVisitTypeByUuid("759799ab-c9a5-435e-b671-77773ada74e4");
    assertNotNull(visitType);
    assertEquals("Return TB Clinic Visit", visitType.getName());

    visitType = Context.getVisitService().getVisitTypeByUuid("759799ab-c9a5-435e-b671-77773ada74e6");
    assertNotNull(visitType);
    assertEquals("Hospitalization", visitType.getName());

    visitType = Context.getVisitService().getVisitTypeByUuid("759799ab-c9a5-435e-b671-77773ada74e1");
    Assert.assertNull(visitType);
}

From source file:org.openmrs.api.VisitServiceTest.java

@Test
@Verifies(value = "should retire given visit type", method = "retireVisitType(VisitType, String)")
public void retireVisitType_shouldRetireGivenVisitType() throws Exception {
    VisitType visitType = Context.getVisitService().getVisitType(1);
    assertNotNull(visitType);// w  w  w  .  jav  a 2s  . c om
    Assert.assertFalse(visitType.isRetired());
    Assert.assertNull(visitType.getRetireReason());

    Context.getVisitService().retireVisitType(visitType, "retire reason");

    visitType = Context.getVisitService().getVisitType(1);
    assertNotNull(visitType);
    assertTrue(visitType.isRetired());
    assertEquals("retire reason", visitType.getRetireReason());

    //Should not change the number of visit types.
    assertEquals(3, Context.getVisitService().getAllVisitTypes().size());
}