Java Code Examples for org.junit.rules.ExpectedException#none()

The following examples show how to use org.junit.rules.ExpectedException#none() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultMapperTest.java    From protobuf-converter with MIT License 6 votes vote down vote up
@Test
public void testMapObjectToDomain() throws MappingException {
	exception = ExpectedException.none();

	MappingResult result = mapper.mapToDomainField(findDomainField("floatValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.MAPPED, testProtobuf.getFloatValue(), testDomain);

	result = mapper.mapToDomainField(findDomainField("doubleValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.MAPPED, testProtobuf.getDoubleValue(), testDomain);

	result = mapper.mapToDomainField(findDomainField("intValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.MAPPED, testProtobuf.getIntValue(), testDomain);

	result = mapper.mapToDomainField(findDomainField("longValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.MAPPED, testProtobuf.getLongValue(), testDomain);

	result = mapper.mapToDomainField(findDomainField("stringValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.MAPPED, testProtobuf.getStringValue(), testDomain);

}
 
Example 2
Source File: DefaultMapperTest.java    From protobuf-converter with MIT License 6 votes vote down vote up
@Test
public void testMapObjectToProtobuf() throws MappingException {
	exception = ExpectedException.none();
	MappingProto.MappingTest.Builder protobufBuilder = MappingProto.MappingTest.newBuilder();
	MappingResult result = mapper.mapToProtobufField(findDomainField("boolValue"), testDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, testDomain.getBoolValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findDomainField("floatValue"), testDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, testDomain.getFloatValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findDomainField("doubleValue"), testDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, testDomain.getDoubleValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findDomainField("intValue"), testDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, testDomain.getIntValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findDomainField("longValue"), testDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, testDomain.getLongValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findDomainField("stringValue"), testDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, testDomain.getStringValue(), protobufBuilder);
}
 
Example 3
Source File: TestThriftHttpServer.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testExceptionThrownWhenMisConfigured() throws IOException {
  Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
  conf.set("hbase.thrift.security.qop", "privacy");
  conf.setBoolean("hbase.thrift.ssl.enabled", false);
  ExpectedException thrown = ExpectedException.none();
  ThriftServerRunner tsr = null;
  try {
    thrown.expect(IllegalArgumentException.class);
    thrown.expectMessage("Thrift HTTP Server's QoP is privacy, " +
        "but hbase.thrift.ssl.enabled is false");
    tsr = TestThriftServerCmdLine.createBoundServer(() -> new ThriftServer(conf));
    fail("Thrift HTTP Server starts up even with wrong security configurations.");
  } catch (Exception e) {
    LOG.info("Expected!", e);
  } finally {
    if (tsr != null) {
      tsr.close();
    }
  }
}
 
Example 4
Source File: DefaultMapperTest.java    From protobuf-converter with MIT License 6 votes vote down vote up
@Test
public void testMapPrimitiveToProtobuf() throws MappingException {
	exception = ExpectedException.none();
	MappingProto.MappingTest.Builder protobufBuilder = MappingProto.MappingTest.newBuilder();
	MappingResult result = mapper
			.mapToProtobufField(findPrimitiveField("booleanValue"), primitiveTestDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, primitiveTestDomain.isBooleanValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findPrimitiveField("floatValue"), primitiveTestDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, primitiveTestDomain.getFloatValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findPrimitiveField("doubleValue"), primitiveTestDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, primitiveTestDomain.getDoubleValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findPrimitiveField("intValue"), primitiveTestDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, primitiveTestDomain.getIntValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findPrimitiveField("longValue"), primitiveTestDomain, protobufBuilder);
	testMappingResult(result, Result.MAPPED, primitiveTestDomain.getLongValue(), protobufBuilder);

}
 
Example 5
Source File: DefaultMapperTest.java    From protobuf-converter with MIT License 5 votes vote down vote up
@Test
public void testMapFieldWithDifferentNameToDomain() throws MappingException {
	exception = ExpectedException.none();
	MappingResult result = mapper.mapToDomainField(findDomainField("boolValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.MAPPED, testProtobuf.getBooleanValue(), testDomain);
	result = mapper.mapToDomainField(findDomainField("simpleListValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.COLLECTION_MAPPING, testProtobuf.getStringListValueList(), testDomain);
}
 
Example 6
Source File: WSSystemTest.java    From candybean with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
@Ignore("This test should pass, but takes a full minute to do so because it" +
		"waits for the response to time out.")
public void testResponseError() {
	ExpectedException exception = ExpectedException.none();
	try {
		exception.expect(CandybeanException.class);
		// Send to an IP address that does not exist
		response = WS.request(WS.OP.POST, "http://240.0.0.0", headers, "", ContentType.DEFAULT_TEXT);
		Assert.fail();
	} catch (CandybeanException e) {
		Assert.assertEquals("Connect to 240.0.0.0:80 [/240.0.0.0] failed: Operation timed out", e.getMessage());
	}
}
 
Example 7
Source File: WSSystemTest.java    From candybean with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void testHTTPError() {
	ExpectedException exception = ExpectedException.none();
	try {
		exception.expect(CandybeanException.class);
		response = WS.request(WS.OP.POST, uri + "/get", headers, "", ContentType.DEFAULT_TEXT);
		Assert.fail();
	} catch (CandybeanException e) {
		Assert.assertEquals("HTTP request received HTTP code: 405",
				e.getMessage().split("\n")[0]);
	}
}
 
Example 8
Source File: OptionDefaultValueConversionTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertDefaultValue() {
  // assert
  thrown = ExpectedException.none();

  // act
  optionDefinitionUnderTest.getDefaultValue();
}
 
Example 9
Source File: AcquisitionTimeoutIT.java    From java-uniqueid with Apache License 2.0 5 votes vote down vote up
@Test
public void timeoutTestNull() throws KeeperException, InterruptedException, IOException {
    claimLockingTicket(zookeeperConnection.getActiveConnection(), znode);

    thrown = ExpectedException.none();

    Timer timer = new Timer();
    timer.schedule(new TimerTask() {
        @Override
        public void run() {
            System.out.println("TIMER");
            try {
                deleteLockingTicket(zookeeperConnection.getActiveConnection(), znode);
            } catch (KeeperException | InterruptedException e) {
                e.printStackTrace();
            }
        }
    }, 2000);

    ResourceClaim claim = ExpiringResourceClaim.claimExpiring(
            zookeeperConnection,
            64,
            znode,
            Duration.ofSeconds(2),
            Duration.ofSeconds(5)
    );

    int resource = claim.get();
    assertThat(claim.state, is(ResourceClaim.State.HAS_CLAIM));
    assertThat(resource, is(both(greaterThanOrEqualTo(0)).and(lessThan(64))));
}
 
Example 10
Source File: NetworkServiceDescriptorManagementClassSuiteTest.java    From NFVO with Apache License 2.0 5 votes vote down vote up
@Test
public void nsdManagementOnboardTest()
    throws NotFoundException, BadFormatException, NetworkServiceIntegrityException,
        CyclicDependenciesException, EntityInUseException, BadRequestException, IOException,
        AlreadyExistingException, PluginException, IncompatibleVNFPackage, VimException,
        InterruptedException, EntityUnreachableException {

  NetworkServiceDescriptor nsd_exp = createNetworkServiceDescriptor();

  when(vnfmManagerEndpointRepository.findAll())
      .thenReturn(
          new ArrayList<VnfmManagerEndpoint>() {
            {
              VnfmManagerEndpoint vnfmManagerEndpoint = new VnfmManagerEndpoint();
              vnfmManagerEndpoint.setEndpoint("test");
              vnfmManagerEndpoint.setType("test");
              vnfmManagerEndpoint.setActive(true);
              vnfmManagerEndpoint.setEnabled(true);
              add(vnfmManagerEndpoint);
            }
          });

  when(nsdRepository.save(nsd_exp)).thenReturn(nsd_exp);
  exception = ExpectedException.none();
  nsdManagement.onboard(nsd_exp, projectId);
  assertEqualsNSD(nsd_exp);
}
 
Example 11
Source File: DefaultMapperTest.java    From protobuf-converter with MIT License 5 votes vote down vote up
@Test
public void testMapNestedToProtobuf() throws MappingException {
	exception = ExpectedException.none();
	MappingProto.MappingTest.Builder protobufBuilder = MappingProto.MappingTest.newBuilder();
	MappingResult result = mapper.mapToProtobufField(findDomainField("nestedValue"), testDomain, protobufBuilder);
	testMappingResult(result, Result.NESTED_MAPPING, testDomain.getNestedValue(), protobufBuilder);
}
 
Example 12
Source File: DefaultMapperTest.java    From protobuf-converter with MIT License 5 votes vote down vote up
@Test
public void testMapCollectionToProtobuf() throws MappingException {
	exception = ExpectedException.none();
	MappingProto.MappingTest.Builder protobufBuilder = MappingProto.MappingTest.newBuilder();
	MappingResult result = mapper
			.mapToProtobufField(findDomainField("simpleListValue"), testDomain, protobufBuilder);
	testMappingResult(result, Result.COLLECTION_MAPPING, testDomain.getSimpleListValue(), protobufBuilder);

	result = mapper.mapToProtobufField(findDomainField("nestedListValue"), testDomain, protobufBuilder);
	testMappingResult(result, Result.COLLECTION_MAPPING, testDomain.getNestedListValue(), protobufBuilder);
}
 
Example 13
Source File: DefaultMapperTest.java    From protobuf-converter with MIT License 5 votes vote down vote up
@Test
public void testMapCollectionToDomain() throws MappingException {
	exception = ExpectedException.none();
	MappingResult result = mapper.mapToDomainField(findDomainField("simpleListValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.COLLECTION_MAPPING, testProtobuf.getStringListValueList(), testDomain);

	result = mapper.mapToDomainField(findDomainField("nestedListValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.COLLECTION_MAPPING, testProtobuf.getNestedListValueList(), testDomain);
}
 
Example 14
Source File: JsonReaderTestCase.java    From vespa with Apache License 2.0 4 votes vote down vote up
@After
public void tearDown() throws Exception {
    types = null;
    parserFactory = null;
    exception = ExpectedException.none();
}
 
Example 15
Source File: ZookeeperConfigAutoConfigurationTests.java    From spring-cloud-zookeeper with Apache License 2.0 4 votes vote down vote up
@Before
public void setUp() throws Exception {
	expectedException = ExpectedException.none();
	// makes Curator fail faster, otherwise it takes 15 seconds to trigger a retry
	System.setProperty("curator-default-connection-timeout", "0");
}
 
Example 16
Source File: PentahoParquetRecordReaderTest.java    From pentaho-hadoop-shims with Apache License 2.0 4 votes vote down vote up
@Test
public void iterateOverParquetFile() throws Exception {
  ConfigurationProxy conf = new ConfigurationProxy();
  conf.set( "fs.defaultFS", "file:///" );
  Job job = Job.getInstance( conf );
  String marshallStr = null;

  switch ( testType ) {
    case "DATA":
      marshallStr =
        new ParquetInputFieldList( ParquetUtils.createSchema( ValueMetaInterface.TYPE_INTEGER ) ).marshall();
      expectedException = ExpectedException.none();
      break;
    case "EMPTY":
      marshallStr = new SchemaDescription().marshall();
      expectedException.expect( RuntimeException.class );
      break;
    default:
      org.junit.Assert.fail( "Invalid test type used." );
  }

  switch ( provider ) {
    case "APACHE":
      job.getConfiguration()
        .set( org.pentaho.hadoop.shim.common.format.parquet.delegate.apache.ParquetConverter.PARQUET_SCHEMA_CONF_KEY,
          marshallStr );
      org.apache.parquet.hadoop.api.ReadSupport<RowMetaAndData> apacheReadSupport =
        new org.pentaho.hadoop.shim.common.format.parquet.delegate.apache.PentahoParquetReadSupport();
      org.apache.parquet.hadoop.ParquetRecordReader<RowMetaAndData> apacheNativeRecordReader =
        new org.apache.parquet.hadoop.ParquetRecordReader<>( apacheReadSupport,
          org.apache.parquet.hadoop.ParquetInputFormat.getFilter( job.getConfiguration() ) );
      org.apache.parquet.hadoop.ParquetInputFormat<RowMetaAndData> apacheNativeParquetInputFormat =
        new org.apache.parquet.hadoop.ParquetInputFormat<>();
      FileInputFormat.setInputPaths( job, getClass().getClassLoader().getResource( testFile ).toExternalForm() );
      InputSplit apacheInputSplit = apacheNativeParquetInputFormat.getSplits( job ).get( 0 );
      TaskAttemptContextImpl apacheTask = new TaskAttemptContextImpl( job.getConfiguration(), new TaskAttemptID() );
      apacheNativeRecordReader.initialize( apacheInputSplit, apacheTask );
      org.pentaho.hadoop.shim.common.format.parquet.delegate.apache.PentahoParquetRecordReader apacheRecordReader =
        new org.pentaho.hadoop.shim.common.format.parquet.delegate.apache.PentahoParquetRecordReader(
          apacheNativeRecordReader );

      switch ( testType ) {
        case "DATA":
          Assert.assertTrue( apacheRecordReader.iterator().hasNext() );
          Assert.assertNotNull( apacheRecordReader.iterator().next() );
          break;
        case "EMPTY":
          Assert.assertFalse( apacheRecordReader.iterator().hasNext() );
          Assert.assertNull( apacheRecordReader.iterator().next() );
          break;
        default:
          org.junit.Assert.fail( "Invalid test type used." );
      }

      apacheRecordReader.close();
      break;
    case "TWITTER":
      job.getConfiguration()
        .set( org.pentaho.hadoop.shim.common.format.parquet.delegate.twitter.ParquetConverter.PARQUET_SCHEMA_CONF_KEY,
          marshallStr );
      parquet.hadoop.api.ReadSupport<RowMetaAndData> twitterReadSupport =
        new org.pentaho.hadoop.shim.common.format.parquet.delegate.twitter.PentahoParquetReadSupport();
      parquet.hadoop.ParquetRecordReader<RowMetaAndData> twitterNativeRecordReader =
        new parquet.hadoop.ParquetRecordReader<>( twitterReadSupport,
          parquet.hadoop.ParquetInputFormat.getFilter( job.getConfiguration() ) );
      parquet.hadoop.ParquetInputFormat<RowMetaAndData> twitterNativeParquetInputFormat =
        new parquet.hadoop.ParquetInputFormat<>();
      FileInputFormat.setInputPaths( job, getClass().getClassLoader().getResource( testFile ).toExternalForm() );
      InputSplit twitterInputSplit = twitterNativeParquetInputFormat.getSplits( job ).get( 0 );
      TaskAttemptContextImpl twitterTask = new TaskAttemptContextImpl( job.getConfiguration(), new TaskAttemptID() );
      twitterNativeRecordReader.initialize( twitterInputSplit, twitterTask );
      org.pentaho.hadoop.shim.common.format.parquet.delegate.twitter.PentahoParquetRecordReader twitterRecordReader =
        new org.pentaho.hadoop.shim.common.format.parquet.delegate.twitter.PentahoParquetRecordReader(
          twitterNativeRecordReader );

      switch ( testType ) {
        case "DATA":
          Assert.assertTrue( twitterRecordReader.iterator().hasNext() );
          Assert.assertNotNull( twitterRecordReader.iterator().next() );
          break;
        case "EMPTY":
          Assert.assertFalse( twitterRecordReader.iterator().hasNext() );
          Assert.assertNull( twitterRecordReader.iterator().next() );
          break;
        default:
          org.junit.Assert.fail( "Invalid test type used." );
      }

      twitterRecordReader.close();
      break;
    default:
      org.junit.Assert.fail( "Invalid provider name used." );
  }
}
 
Example 17
Source File: DefaultMapperTest.java    From protobuf-converter with MIT License 4 votes vote down vote up
@Test
public void testMapNestedToDomain() throws MappingException {
	exception = ExpectedException.none();
	MappingResult result = mapper.mapToDomainField(findDomainField("nestedValue"), testProtobuf, testDomain);
	testMappingResult(result, Result.NESTED_MAPPING, testProtobuf.getNestedValue(), testDomain);
}
 
Example 18
Source File: GoogleAnalyticsApiFacadeTest.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public GoogleAnalyticsApiFacadeTest( String path, Class<Exception> expectedExceptionClass ) {
  this.path = path;

  this.expectedException = ExpectedException.none();
  this.expectedException.expect( expectedExceptionClass );
}