Java Code Examples for org.testng.annotations.Test

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project action-core, under directory /src/test/java/com/ning/metrics/action/hdfs/data/parser/.

Source file: TestSmileRowSerializer.java

  15 
vote

@Test(groups="fast") public void testToRowsOrderingWithoutRegistrar() throws Exception {
  final Map<String,Object> eventMap=createEventMap();
  final ByteArrayOutputStream out=createSmileEnvelopePayload(eventMap);
  final InputStream stream=new ByteArrayInputStream(out.toByteArray());
  final SmileRowSerializer serializer=new SmileRowSerializer();
  final Rows rows=serializer.toRows(new NullRegistrar(),stream);
  final RowSmile firstRow=(RowSmile)rows.iterator().next();
  final ImmutableMap<String,ValueNode> actual=firstRow.toMap();
  Assert.assertEquals(actual.keySet().size(),eventMap.keySet().size() + 2);
  Assert.assertNotNull(actual.get("eventDate"));
  Assert.assertEquals(actual.get("eventGranularity"),"HOURLY");
  Assert.assertEquals(actual.get("field1"),eventMap.get("field1"));
  Assert.assertEquals(actual.get("field2"),eventMap.get("field2"));
}
 

Example 2

From project action-core, under directory /src/test/java/com/ning/metrics/action/hdfs/data/parser/.

Source file: TestSmileRowSerializer.java

  15 
vote

@Test(groups="fast") public void testToRowsOrderingWithRegistrar() throws Exception {
  final Map<String,Object> eventMap=createEventMap();
  final ByteArrayOutputStream out=createSmileEnvelopePayload(eventMap);
  final InputStream stream=new ByteArrayInputStream(out.toByteArray());
  final SmileRowSerializer serializer=new SmileRowSerializer();
  final Rows rows=serializer.toRows(new SomeRegistrar(),stream);
  final RowSmile firstRow=(RowSmile)rows.iterator().next();
  final ImmutableMap<String,ValueNode> actual=firstRow.toMap();
  Assert.assertEquals(actual.keySet().size(),eventMap.keySet().size() + 1);
  Assert.assertNotNull(actual.get("eventDate"));
  Assert.assertEquals(actual.get("field1"),eventMap.get("field1"));
  Assert.assertEquals(actual.get("field2"),eventMap.get("field2"));
}
 

Example 3

From project action-core, under directory /src/test/java/com/ning/metrics/action/hdfs/writer/.

Source file: TestHdfsWriter.java

  15 
vote

@Test(groups="fast") public void testWrite() throws Exception {
  final HdfsWriter writer=new HdfsWriter(fileSystemAccess);
  final String outputFile=outputPath + "/lorem.txt";
  final URI outputURI=writer.write(new FileInputStream(file),outputFile,false,(short)1,1024,"ugo=r");
  final FileStatus status=fileSystemAccess.get().getFileStatus(new Path(outputURI));
  Assert.assertEquals(status.getPath().toString(),"file:" + outputFile);
  Assert.assertEquals(status.getReplication(),(short)1);
  try {
    writer.write(new FileInputStream(file),outputFile,false,(short)1,1024,"ugo=r");
    Assert.fail();
  }
 catch (  IOException e) {
    Assert.assertEquals(e.getLocalizedMessage(),String.format("File already exists:%s",outputFile));
  }
}
 

Example 4

From project adbcj, under directory /api/src/test/java/org/adbcj/support/.

Source file: DecoderInputStreamTest.java

  15 
vote

@Test public void boundingTest() throws IOException {
  InputStream in=new ByteArrayInputStream(new byte[]{0,1});
  InputStream din=new DecoderInputStream(in,1);
  din.read();
  try {
    din.read();
    Assert.fail("Should have thrown indicating limit exceeded");
  }
 catch (  IllegalStateException e) {
  }
}
 

Example 5

From project adbcj, under directory /api/src/test/java/org/adbcj/support/.

Source file: DecoderInputStreamTest.java

  15 
vote

@Test public void readString() throws IOException {
  final String charset="UTF-8";
  final String s="Have a nice day!";
  byte[] input=(s + "\0").getBytes(charset);
  InputStream bais=new ByteArrayInputStream(input);
  DecoderInputStream in=new DecoderInputStream(bais);
  in.setLimit(input.length);
  String i=in.readString(Charset.forName(charset));
  Assert.assertEquals(s,i);
}
 

Example 6

From project adbcj, under directory /mysql/codec/src/test/java/org/adbcj/mysql/codec/.

Source file: GreetingDecodeTest.java

  15 
vote

@Test public void decodeGreeting1() throws IOException {
  InputStream in=new ByteArrayInputStream(GREETING1);
  MySqlClientDecoder decoder=new MySqlClientDecoder();
  ServerGreeting greeting=(ServerGreeting)decoder.decode(in,true);
  Assert.assertEquals(greeting.getPacketLength(),64);
  Assert.assertEquals(greeting.getPacketNumber(),0);
  Assert.assertEquals(greeting.getProtocol(),10);
  Assert.assertEquals(greeting.getVersion(),"5.0.51a-3ubuntu5.1");
  Assert.assertEquals(greeting.getThreadId(),831);
  Assert.assertEquals(greeting.getSalt(),new byte[]{(byte)0x58,(byte)0x63,(byte)0x67,(byte)0x5b,(byte)0x71,(byte)0x49,(byte)0x58,(byte)0x5f,(byte)0x55,(byte)0x69,(byte)0x33,(byte)0x5f,(byte)0x64,(byte)0x5a,(byte)0x75,(byte)0x5f,(byte)0x5c,(byte)0x31,(byte)0x7c,(byte)0x41});
  Assert.assertEquals(greeting.getServerCapabilities(),EnumSet.of(ClientCapabilities.LONG_COLUMN_FLAG,ClientCapabilities.CONNECT_WITH_DB,ClientCapabilities.COMPRESS,ClientCapabilities.PROTOCOL_4_1,ClientCapabilities.TRANSACTIONS,ClientCapabilities.SECURE_AUTHENTICATION));
  Assert.assertEquals(greeting.getCharacterSet(),MysqlCharacterSet.LATIN1_SWEDISH_CI);
  Assert.assertEquals(greeting.getServerStatus(),EnumSet.of(ServerStatus.AUTO_COMMIT));
}
 

Example 7

From project adbcj, under directory /mysql/codec/src/test/java/org/adbcj/mysql/codec/.

Source file: GreetingDecodeTest.java

  15 
vote

@Test public void decodeGreeting2() throws IOException {
  InputStream in=new ByteArrayInputStream(GREETING2);
  MySqlClientDecoder decoder=new MySqlClientDecoder();
  ServerGreeting greeting=(ServerGreeting)decoder.decode(in,true);
  Assert.assertEquals(greeting.getPacketLength(),74);
  Assert.assertEquals(greeting.getPacketNumber(),0);
  Assert.assertEquals(greeting.getProtocol(),10);
  Assert.assertEquals(greeting.getVersion(),"5.0.38-Ubuntu_0ubuntu1.4-log");
  Assert.assertEquals(greeting.getThreadId(),41344);
  Assert.assertEquals(greeting.getSalt(),new byte[]{(byte)0x72,(byte)0x5a,(byte)0x4d,(byte)0x53,(byte)0x39,(byte)0x5f,(byte)0x56,(byte)0x71,(byte)0x58,(byte)0x41,(byte)0x7c,(byte)0x6d,(byte)0x31,(byte)0x47,(byte)0x51,(byte)0x43,(byte)0x3b,(byte)0x3d,(byte)0x62,(byte)0x53});
  Assert.assertEquals(greeting.getServerCapabilities(),EnumSet.of(ClientCapabilities.LONG_COLUMN_FLAG,ClientCapabilities.CONNECT_WITH_DB,ClientCapabilities.COMPRESS,ClientCapabilities.PROTOCOL_4_1,ClientCapabilities.TRANSACTIONS,ClientCapabilities.SECURE_AUTHENTICATION));
  Assert.assertEquals(greeting.getCharacterSet(),MysqlCharacterSet.LATIN1_SWEDISH_CI);
  Assert.assertEquals(greeting.getServerStatus(),EnumSet.of(ServerStatus.AUTO_COMMIT));
}
 

Example 8

From project adbcj, under directory /mysql/codec/src/test/java/org/adbcj/mysql/codec/.

Source file: IoUtilsTest.java

  15 
vote

@Test public void testSafeRead() throws IOException {
  InputStream in=new ByteArrayInputStream(new byte[]{0,1,2});
  Assert.assertEquals(IoUtils.safeRead(in),0);
  Assert.assertEquals(IoUtils.safeRead(in),1);
  Assert.assertEquals(IoUtils.safeRead(in),2);
  try {
    IoUtils.safeRead(in);
    Assert.fail("Did not throw EOF exception");
  }
 catch (  EOFException e) {
  }
}
 

Example 9

From project adbcj, under directory /mysql/codec/src/test/java/org/adbcj/mysql/codec/.

Source file: IoUtilsTest.java

  15 
vote

@Test(dependsOnMethods="testSafeRead") public void testReadShort() throws IOException {
  ByteBuffer buffer=ByteBuffer.allocate(1024);
  buffer.order(ByteOrder.LITTLE_ENDIAN);
  buffer.putShort((short)0).putShort((short)1).putShort((short)2).putShort((short)-1).putShort((short)-2);
  InputStream in=new ByteArrayInputStream(buffer.array(),0,buffer.position());
  Assert.assertEquals(IoUtils.readShort(in),0);
  Assert.assertEquals(IoUtils.readShort(in),1);
  Assert.assertEquals(IoUtils.readShort(in),2);
  Assert.assertEquals(IoUtils.readShort(in),-1);
  Assert.assertEquals(IoUtils.readShort(in),-2);
}
 

Example 10

From project adt-maven-plugin, under directory /src/test/java/com/yelbota/plugins/adt/.

Source file: DependencyAdtMojoTest.java

  15 
vote

@Test public void getAirSdkArtifactTest1() throws Exception {
  List<Artifact> artifactList=new ArrayList<Artifact>();
  ArtifactStub stub=new ArtifactStub();
  stub.setGroupId("com.adobe.air");
  stub.setArtifactId("air-sdk");
  artifactList.add(stub);
  DependencyAdtMojo adtMojo=new DependencyAdtMojo();
  adtMojo.pluginArtifacts=artifactList;
  Assert.assertNotNull(adtMojo.getAirSdkArtifact());
}
 

Example 11

From project adt-maven-plugin, under directory /src/test/java/com/yelbota/plugins/adt/.

Source file: DependencyAdtMojoTest.java

  15 
vote

@Test public void getAirSdkArtifactTest2() throws Exception {
  List<Artifact> artifactList=new ArrayList<Artifact>();
  ArtifactStub stub=new ArtifactStub();
  stub.setArtifactId("");
  stub.setGroupId("");
  artifactList.add(stub);
  DependencyAdtMojo adtMojo=new DependencyAdtMojo();
  adtMojo.pluginArtifacts=artifactList;
  try {
    adtMojo.getAirSdkArtifact();
    Assert.fail("no dependency or sdk-version defined");
  }
 catch (  MojoFailureException e) {
  }
}
 

Example 12

From project adt-maven-plugin, under directory /src/test/java/com/yelbota/plugins/adt/.

Source file: DependencyAdtMojoTest.java

  15 
vote

@Test public void getSDKArtifactPackagingTest() throws Exception {
  DependencyAdtMojo adtMojo=new DependencyAdtMojo();
  String p=adtMojo.getSDKArtifactPackaging("3.1",DependencyAdtMojo.OS_CLASSIFIER_WINDOWS);
  Assert.assertEquals(p,DependencyAdtMojo.ZIP);
  p=adtMojo.getSDKArtifactPackaging("3.1",DependencyAdtMojo.OS_CLASSIFIER_MAC);
  Assert.assertEquals(p,DependencyAdtMojo.ZIP);
  p=adtMojo.getSDKArtifactPackaging("3.2-RC1",DependencyAdtMojo.OS_CLASSIFIER_MAC);
  Assert.assertEquals(p,DependencyAdtMojo.ZIP);
  p=adtMojo.getSDKArtifactPackaging("3.4",DependencyAdtMojo.OS_CLASSIFIER_WINDOWS);
  Assert.assertEquals(p,DependencyAdtMojo.ZIP);
  p=adtMojo.getSDKArtifactPackaging("3.4",DependencyAdtMojo.OS_CLASSIFIER_MAC);
  Assert.assertEquals(p,DependencyAdtMojo.TBZ2);
  p=adtMojo.getSDKArtifactPackaging("3.4-beta-1",DependencyAdtMojo.OS_CLASSIFIER_MAC);
  Assert.assertEquals(p,DependencyAdtMojo.TBZ2);
}
 

Example 13

From project adt-maven-plugin, under directory /src/test/java/com/yelbota/plugins/adt/model/.

Source file: ApplicationDescriptorModelTest.java

  15 
vote

@Test public void configureDescriptorTest(){
  try {
    File f=FileUtils.resolveFile(wd,"src/test/resources/unit/application-descriptor.xml");
    ApplicationDescriptorModel c=new ApplicationDescriptorModel(f);
    List<String> extensionIds=new ArrayList<String>();
    extensionIds.add("com.example.Ext1");
    extensionIds.add("ext2");
    c.setVersionLabel("1.0-SNAPSHOT");
    c.setVersionNumber("1.0.0");
    c.setContent("application-1.0-SNAPSHOT.swf");
    c.setExtensionIds(extensionIds);
    c.configureDescriptor();
    testDom(c.getDom(),c);
  }
 catch (  MojoFailureException e) {
    Assert.fail(e.toString());
  }
catch (  XPathExpressionException e) {
    Assert.fail("Fail during test execution " + e);
  }
}
 

Example 14

From project adt-maven-plugin, under directory /src/test/java/com/yelbota/plugins/adt/model/.

Source file: ApplicationDescriptorModelTest.java

  15 
vote

@Test public void configureDescriptorWithExtensionsTagTest(){
  try {
    File f=FileUtils.resolveFile(wd,"src/test/resources/unit/application-descriptor-with-extensions-tag.xml");
    ApplicationDescriptorModel c=new ApplicationDescriptorModel(f);
    List<String> extensionIds=new ArrayList<String>();
    extensionIds.add("com.example.Ext1");
    extensionIds.add("ext2");
    c.setExtensionIds(extensionIds);
    c.configureDescriptor();
    testDomExtensions(c.getDom(),c);
  }
 catch (  MojoFailureException e) {
    Assert.fail(e.toString());
  }
catch (  XPathExpressionException e) {
    Assert.fail("Fail during test execution " + e);
  }
}
 

Example 15

From project adt-maven-plugin, under directory /src/test/java/com/yelbota/plugins/adt/model/.

Source file: ApplicationDescriptorModelTest.java

  15 
vote

@Test public void printToFileTest(){
  try {
    File f=FileUtils.resolveFile(wd,"src/test/resources/unit/application-descriptor.xml");
    ApplicationDescriptorModel c=new ApplicationDescriptorModel(f);
    c.setVersionLabel("1.0-SNAPSHOT");
    c.setVersionNumber("1.0.0");
    c.setContent("application-1.0-SNAPSHOT.swf");
    f=FileUtils.resolveFile(wd,"target/unit/application-descriptor.xml");
    f.getParentFile().mkdirs();
    c.printToFile(f);
    DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();
    DocumentBuilder db=dbf.newDocumentBuilder();
    Document dom=db.parse(f);
    testDom(dom,c);
  }
 catch (  MojoFailureException e) {
    Assert.fail(e.toString());
  }
catch (  XPathExpressionException e) {
    Assert.fail("Fail during test execution " + e);
  }
catch (  ParserConfigurationException e) {
    Assert.fail("Fail during test execution " + e);
  }
catch (  SAXException e) {
    Assert.fail("Fail during test execution " + e);
  }
catch (  IOException e) {
    Assert.fail("Fail during test execution " + e);
  }
}
 

Example 16

From project airlift, under directory /bootstrap/src/test/java/io/airlift/bootstrap/.

Source file: TestBootstrap.java

  15 
vote

@Test public void testRequiresExplicitBindings() throws Exception {
  Bootstrap bootstrap=new Bootstrap();
  try {
    bootstrap.initialize().getInstance(Instance.class);
    Assert.fail("should require explicit bindings");
  }
 catch (  ConfigurationException e) {
    Assertions.assertContains(e.getErrorMessages().iterator().next().getMessage(),"Explicit bindings are required");
  }
}
 

Example 17

From project airlift, under directory /bootstrap/src/test/java/io/airlift/bootstrap/.

Source file: TestBootstrap.java

  15 
vote

@Test public void testDoesNotAllowCircularDependencies() throws Exception {
  Bootstrap bootstrap=new Bootstrap(new Module(){
    @Override public void configure(    Binder binder){
      binder.bind(InstanceA.class);
      binder.bind(InstanceB.class);
    }
  }
);
  try {
    bootstrap.initialize().getInstance(InstanceA.class);
    Assert.fail("should not allow circular dependencies");
  }
 catch (  ProvisionException e) {
    Assertions.assertContains(e.getErrorMessages().iterator().next().getMessage(),"circular proxies are disabled");
  }
}
 

Example 18

From project airlift, under directory /bootstrap/src/test/java/io/airlift/bootstrap/.

Source file: TestLifeCycleManager.java

  15 
vote

@Test public void testImmediateStarts() throws Exception {
  Module module=new Module(){
    @Override public void configure(    Binder binder){
      binder.bind(InstanceThatRequiresStart.class).in(Scopes.SINGLETON);
      binder.bind(InstanceThatUsesInstanceThatRequiresStart.class).in(Scopes.SINGLETON);
    }
  }
;
  Injector injector=Guice.createInjector(Stage.PRODUCTION,new LifeCycleModule(),module);
  LifeCycleManager lifeCycleManager=injector.getInstance(LifeCycleManager.class);
  lifeCycleManager.start();
  Assert.assertEquals(stateLog,Arrays.asList("InstanceThatUsesInstanceThatRequiresStart:OK"));
}
 

Example 19

From project airlift, under directory /bootstrap/src/test/java/io/airlift/bootstrap/.

Source file: TestLifeCycleManager.java

  15 
vote

@Test public void testPrivateModule() throws Exception {
  Module module=new Module(){
    @Override public void configure(    Binder binder){
      final PrivateModule privateModule=new PrivateModule(){
        @Override protected void configure(){
          binder().bind(SimpleBase.class).to(SimpleBaseImpl.class).in(Scopes.SINGLETON);
          binder().expose(SimpleBase.class);
        }
      }
;
      binder.install(privateModule);
    }
  }
;
  Injector injector=Guice.createInjector(Stage.PRODUCTION,new LifeCycleModule(),module);
  LifeCycleManager lifeCycleManager=injector.getInstance(LifeCycleManager.class);
  lifeCycleManager.start();
  Assert.assertEquals(stateLog,Arrays.asList("postSimpleBaseImpl"));
  lifeCycleManager.stop();
  Assert.assertEquals(stateLog,Arrays.asList("postSimpleBaseImpl","preSimpleBaseImpl"));
}
 

Example 20

From project airlift, under directory /bootstrap/src/test/java/io/airlift/bootstrap/.

Source file: TestLifeCycleManager.java

  15 
vote

@Test public void testSubClassAnnotated() throws Exception {
  Module module=new Module(){
    @Override public void configure(    Binder binder){
      binder.bind(SimpleBase.class).to(SimpleBaseImpl.class).in(Scopes.SINGLETON);
    }
  }
;
  Injector injector=Guice.createInjector(Stage.PRODUCTION,new LifeCycleModule(),module);
  LifeCycleManager lifeCycleManager=injector.getInstance(LifeCycleManager.class);
  lifeCycleManager.start();
  Assert.assertEquals(stateLog,Arrays.asList("postSimpleBaseImpl"));
  lifeCycleManager.stop();
  Assert.assertEquals(stateLog,Arrays.asList("postSimpleBaseImpl","preSimpleBaseImpl"));
}
 

Example 21

From project airlift, under directory /bootstrap/src/test/java/io/airlift/bootstrap/.

Source file: TestLifeCycleManager.java

  15 
vote

@Test public void testExecuted() throws Exception {
  Injector injector=Guice.createInjector(Stage.PRODUCTION,new LifeCycleModule(),new Module(){
    @Override public void configure(    Binder binder){
      binder.bind(ExecutedInstance.class).in(Scopes.SINGLETON);
    }
  }
);
  ExecutedInstance instance=injector.getInstance(ExecutedInstance.class);
  LifeCycleManager lifeCycleManager=injector.getInstance(LifeCycleManager.class);
  lifeCycleManager.start();
  instance.waitForStart();
  Assert.assertEquals(stateLog,Arrays.asList("Starting"));
  lifeCycleManager.stop();
  instance.waitForEnd();
  Assert.assertEquals(stateLog,Arrays.asList("Starting","Done"));
}