下面列出了org.testng.Assert#assertSame ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testSystemNotInitialized() throws Exception {
// Unset any configuration dir if it is set by another test
System.getProperties().remove(ConfigurationConstants.SYSPROP_CONFIG_DIR);
Properties bootProps = new Properties();
bootProps.setProperty(ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER,
PropertiesConfigurationProvider.class.getCanonicalName());
Properties configProps = new Properties();
SqoopTestUtils.setupTestConfigurationUsingProperties(bootProps, configProps);
try {
SqoopConfiguration.getInstance().initialize();
RepositoryManager.getInstance().initialize();
} catch (Exception ex) {
Assert.assertTrue(ex instanceof SqoopException);
Assert.assertSame(((SqoopException) ex).getErrorCode(),
RepositoryError.REPO_0001);
}
}
@Test
public void testQuerySubmissionOneInstanceIsTheSameInstance() throws Exception {
config.set(DRPCConfig.PUBSUB_CONTEXT_NAME, PubSub.Context.QUERY_SUBMISSION.name());
DRPCPubSub pubSub = new DRPCPubSub(config);
Publisher publisher = pubSub.getPublisher();
Subscriber subscriber = pubSub.getSubscriber();
Assert.assertSame(publisher, subscriber);
// All future calls just return the same instance
Assert.assertSame(publisher, pubSub.getPublisher());
Assert.assertSame(subscriber, pubSub.getSubscriber());
Assert.assertSame(pubSub.getPublisher(), pubSub.getSubscriber());
// So do calls to get multiples after
List<Publisher> publishers = pubSub.getPublishers(42);
List<Subscriber> subscribers = pubSub.getSubscribers(20);
Assert.assertEquals(publishers.size(), 1);
Assert.assertEquals(subscribers.size(), 1);
Assert.assertEquals(publishers.get(0), publisher);
Assert.assertEquals(subscribers.get(0), subscriber);
}
@Test
public void test3() throws Exception {
SAXTransformerFactory sf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
Transformer t = sf.newTransformer();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder parser = dbf.newDocumentBuilder();
Document dom = parser.parse(Bug5072946.class.getResourceAsStream("Bug5072946.xml"));
DOMResult r = new DOMResult();
t.transform(new DOMSource(dom), r);
Assert.assertNotNull(r.getNode());
Node n = r.getNode().getFirstChild();
r.setNode(n);
t.transform(new DOMSource(dom), r);
Assert.assertNotNull(r.getNode());
Assert.assertSame(r.getNode(), n);
r.setNextSibling(r.getNode().getFirstChild());
t.transform(new DOMSource(dom), r);
Assert.assertNotNull(r.getNode());
Assert.assertSame(r.getNode(), n);
}
@Test
public void testLongFormNamesForTypos() {
// We avoid a direct comparison of the constant value (rather than indirectly using its name)
// because that would typos and here the names matter and are unlikely to change even in the long term.
Assert.assertSame(constantNameToInstance("ADENINE"), Nucleotide.A);
Assert.assertSame(constantNameToInstance("THYMINE"), Nucleotide.T);
Assert.assertSame(constantNameToInstance("GUANINE"), Nucleotide.G);
Assert.assertSame(constantNameToInstance("CYTOSINE"), Nucleotide.C);
Assert.assertSame(constantNameToInstance("URACIL"), Nucleotide.U);
Assert.assertSame(constantNameToInstance("ANY"), Nucleotide.N);
Assert.assertSame(constantNameToInstance("PURINE"), Nucleotide.R);
Assert.assertSame(constantNameToInstance("PYRIMIDINE"), Nucleotide.Y);
Assert.assertSame(constantNameToInstance("INVALID"), Nucleotide.X);
Assert.assertSame(constantNameToInstance("STRONG"), Nucleotide.S);
Assert.assertSame(constantNameToInstance("WEAK"), Nucleotide.W);
Assert.assertSame(constantNameToInstance("KETO"), Nucleotide.K);
Assert.assertSame(constantNameToInstance("AMINO"), Nucleotide.M);
}
@Test
public void testConfigurationProviderInvalid() throws Exception {
boolean success = false;
Properties bootProps = new Properties();
bootProps.setProperty(ConfigurationConstants.BOOTCFG_CONFIG_PROVIDER,
"foobar");
SqoopTestUtils.setupTestConfigurationUsingProperties(bootProps, null);
try {
SqoopConfiguration.getInstance().initialize();
} catch (Exception ex) {
Assert.assertTrue(ex instanceof SqoopException);
Assert.assertSame(((SqoopException) ex).getErrorCode(),
CoreError.CORE_0004);
success = true;
}
Assert.assertTrue(success);
}
@Test
public void testCache() throws Exception
{
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1));
try
{
client.start();
Assert.assertSame(client.usingNamespace("foo"), client.usingNamespace("foo"));
Assert.assertNotSame(client.usingNamespace("foo"), client.usingNamespace("bar"));
}
finally
{
CloseableUtils.closeQuietly(client);
}
}
@Test
public void testPutTwice() {
Integer second = 1;
StorageCache cache = StorageCache.initCache(_configuration);
cache.put(0, 1);
cache.put(0, second);
Assert.assertSame(cache.get(0), second);
}
@Test(dataProvider = "tableColumnsData")
public void testSetAndGetBoolean(final TableColumnCollection columns) {
final DataLine subject = new DataLine(columns, IllegalArgumentException::new);
for (int i = 0; i < columns.columnCount(); i++) {
Assert.assertSame(subject.set(columns.nameAt(i), (i & 1) == 0), subject);
}
for (int i = 0; i < columns.columnCount(); i++) {
Assert.assertEquals(subject.getBoolean(i), 0 == (i & 1));
}
}
@Test(dataProvider = "tableColumnsData")
public void testGetInt(final TableColumnCollection columns) {
final DataLine subject = new DataLine(columns, IllegalArgumentException::new);
for (int i = 0; i < columns.columnCount(); i++) {
Assert.assertSame(subject.set(columns.nameAt(i), i), subject);
}
for (int i = 0; i < columns.columnCount(); i++) {
Assert.assertEquals(subject.getInt(i), i);
}
}
@Test
public void testRegisterTwice() {
ColorSerializer i1 = new ColorSerializer();
ColorSerializer i2 = new ColorSerializer();
_serializers.registerSerializer(i1);
_serializers.registerSerializer(i2);
Assert.assertSame(_serializers.getSerializer(Color.class), i1);
}
@Test
public void testRegister() {
ColorSerializer i = new ColorSerializer();
_serializers.registerSerializer(i);
Assert.assertSame(_serializers.getSerializer(Color.class), i);
Assert.assertEquals(_serializers.getIndex(Color.class), 0);
}
@Test
public void emptySeqPrepend() {
final Seq<Integer> empty = Seq.empty();
final Seq<Integer> seq = Seq.of(1, 2, 3, 4);
final Seq<Integer> aseq = empty.prepend(seq);
Assert.assertEquals(aseq, seq);
Assert.assertSame(aseq, seq);
}
@Test
public void testGetMysqlMatchedStringDataType() {
final MysqlSchemaCodegen codegen = new MysqlSchemaCodegen();
Assert.assertSame(codegen.getMysqlMatchedStringDataType(6, 6), "CHAR");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(0, 0), "CHAR");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, 255), "CHAR");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 100), "VARCHAR");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 255), "VARCHAR");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(50, 255), "VARCHAR");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 20), "VARCHAR");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, null), "TEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, null), "TEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(255, null), "TEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 256), "TEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, null), "MEDIUMTEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777215, 100), "MEDIUMTEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777215), "MEDIUMTEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777215), "MEDIUMTEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, null), "LONGTEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(null, 16777216), "LONGTEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(16777216, 16777216), "LONGTEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, 16777216), "LONGTEXT");
Assert.assertSame(codegen.getMysqlMatchedStringDataType(100, Integer.MAX_VALUE), "LONGTEXT");
}
@Test
public void mapEmptyMSeq() {
final Seq<Integer> integers = Seq.empty();
final Seq<String> strings = integers.map(Object::toString);
Assert.assertSame(integers, strings);
Assert.assertSame(strings, Seq.empty());
}
@Test
public void testProviderReturnsSameInstance() {
DAORegistry daoRegistry = DAORegistry.getInstance();
MergedAnomalyResultManager m1 = daoRegistry.getMergedAnomalyResultDAO();
MergedAnomalyResultManager m2 = daoRegistry.getMergedAnomalyResultDAO();
Assert.assertSame(m1, m2);
}
@Test
public void testConfigInheritanceVals() throws Exception {
ConfigInheritance val = BasicConfigInheritance.NEVER_INHERITED;
ConfigInheritance newVal = assertSerializeAndDeserialize(val);
Assert.assertSame(val, newVal);
}
private void assertMappingIsAsExpected(final SVFastqUtils.Mapping mapping, final String[] contig, final int[] start,
final boolean[] forward, final Cigar[] cigarAlongRef,
final int[] mappingQual, final int[] mismatches,
final int[] alignmentScores) {
Assert.assertEquals(mapping.getAllIntervals().size(), contig.length);
Assert.assertEquals(mapping.isMapped(), contig.length > 0);
if (!mapping.isMapped()) {
Assert.assertNull(mapping.getPrimaryInterval());
Assert.assertTrue(mapping.getSupplementaryIntervals().isEmpty());
Assert.assertEquals(mapping.getCigar(), new Cigar());
Assert.assertNull(mapping.getContig());
Assert.assertEquals(mapping.getStart(), SAMRecord.NO_ALIGNMENT_START);
Assert.assertEquals(mapping.getEnd(), SAMRecord.NO_ALIGNMENT_START);
} else {
Assert.assertEquals(mapping.getSupplementaryIntervals().size(), contig.length - 1);
for (int i = 0; i < contig.length; i++) {
final AlignmentInterval ai = mapping.getAllIntervals().get(i);
Assert.assertNotNull(ai);
Assert.assertEquals(ai.referenceSpan.getContig(), contig[i]);
Assert.assertEquals(ai.referenceSpan.getStart(), start[i]);
Assert.assertEquals(ai.forwardStrand, forward[i]);
Assert.assertEquals(ai.cigarAlongReference(), cigarAlongRef[i]);
Assert.assertEquals(ai.mapQual, mappingQual[i]);
Assert.assertEquals(ai.mismatches, mismatches[i]);
Assert.assertEquals(ai.alnScore, alignmentScores[i]);
if (i == 0) {
Assert.assertSame(ai, mapping.getPrimaryInterval());
Assert.assertEquals(mapping.getCigar(), ai.cigarAlongReference());
Assert.assertEquals(mapping.getContig(), ai.referenceSpan.getContig());
Assert.assertEquals(mapping.getStart(), ai.referenceSpan.getStart());
Assert.assertEquals(mapping.getEnd(), ai.referenceSpan.getEnd());
Assert.assertEquals(mapping.isForwardStrand(), ai.forwardStrand);
} else {
Assert.assertSame(ai, mapping.getSupplementaryIntervals().get(i - 1));
}
}
}
}
@Test (groups = "deserializationTest")
public void testIsSupportedForFastSpecificDatumReader() {
Schema testWriterSchema = Schema.parse("{\"type\": \"record\", \"name\": \"test_record\", \"fields\":[]}");
Schema testReaderSchema = Schema.parse("{\"type\": \"record\", \"name\": \"test_record\", \"fields\":[]}");
FastSpecificDatumReader fastReader = FastDatumReaderWriterUtil.getFastSpecificDatumReader(testWriterSchema, testReaderSchema);
Assert.assertNotNull(fastReader);
FastSpecificDatumReader newFastReader = FastDatumReaderWriterUtil.getFastSpecificDatumReader(testWriterSchema, testReaderSchema);
Assert.assertSame(fastReader, newFastReader);
}
@Test
public void testInterfaceType() throws Throwable {
SerializerWithInterface i = new SerializerWithInterface();
_serializers.registerSerializer(i);
Assert.assertSame(_serializers.getSerializer(AnInterface.class), i);
}
@Test(dataProvider= "correctColumnNamesData")
public void testCheckNamesOnCorrectData(final String[] names) {
Assert.assertSame(TableColumnCollection.checkNames(names, IllegalArgumentException::new), names);
}