Latest Junit Case

import static org.junit.Assert.assertEquals;

import java.net.UnknownHostException;
import java.util.Map;
import java.util.HashMap;

import org.bson.BSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;
import com.mongodb.MongoClient;

public class DataIgest {
static MongoClient mongoClient;
static DBObject myDoc;
static DBCollection coll;
static DBCursor cursor;
static DB db;
static boolean auth;
final static String[] expectedRes = new String[]{
"{AllocBps=null, DestIpAddress=10.200.0.3, DestUdpPort=6100, DvbServiceId=62, RfDvbNetworkId=49722, RfDvbTsid=61222, RfFreqHz=6100000000, RfFreqNo=101, RfInnerFec=3, RfModulation=64, RfNgodS6Name=null, RfOuterFec=7, RfSymPerSec=6400000, SgIngestName=Q1Gob-201} ",
"{AllocBps=null, DestIpAddress=10.200.0.3, DestUdpPort=6101, DvbServiceId=63, RfDvbNetworkId=49722, RfDvbTsid=61222, RfFreqHz=6100000000, RfFreqNo=101, RfInnerFec=3, RfModulation=64, RfNgodS6Name=null, RfOuterFec=7, RfSymPerSec=6400000, SgIngestName=Q1Gob-201} ",
"{AllocBps=null, DestIpAddress=10.200.0.3, DestUdpPort=6102, DvbServiceId=64, RfDvbNetworkId=49722, RfDvbTsid=61222, RfFreqHz=6100000000, RfFreqNo=101, RfInnerFec=3, RfModulation=64, RfNgodS6Name=null, RfOuterFec=7, RfSymPerSec=6400000, SgIngestName=Q1Gob-201} ",
"{AllocBps=null, DestIpAddress=10.200.0.3, DestUdpPort=6103, DvbServiceId=62, RfDvbNetworkId=49722, RfDvbTsid=61222, RfFreqHz=6300000000, RfFreqNo=101, RfInnerFec=3, RfModulation=64, RfNgodS6Name=null, RfOuterFec=7, RfSymPerSec=6400000, SgIngestName=Q1Gob-201} ",
"{AllocBps=null, DestIpAddress=10.200.0.3, DestUdpPort=6104, DvbServiceId=63, RfDvbNetworkId=49722, RfDvbTsid=61230, RfFreqHz=6300000000, RfFreqNo=102, RfInnerFec=3, RfModulation=64, RfNgodS6Name=null, RfOuterFec=7, RfSymPerSec=6400000, SgIngestName=Q1Gob-201} ",
"{AllocBps=null, DestIpAddress=10.200.0.3, DestUdpPort=6105, DvbServiceId=64, RfDvbNetworkId=49722, RfDvbTsid=61230, RfFreqHz=6300000000, RfFreqNo=102, RfInnerFec=3, RfModulation=64, RfNgodS6Name=null, RfOuterFec=7, RfSymPerSec=6400000, SgIngestName=Q1Gob-201} ",
"{AllocBps=null, DestIpAddress=10.200.0.3, DestUdpPort=6106, DvbServiceId=65, RfDvbNetworkId=49722, RfDvbTsid=61230, RfFreqHz=6300000000, RfFreqNo=102, RfInnerFec=3, RfModulation=64, RfNgodS6Name=null, RfOuterFec=7, RfSymPerSec=6400000, SgIngestName=Q1Gob-201} ",
"{AllocBps=null, DestIpAddress=10.200.0.3, DestUdpPort=6116, DvbServiceId=62, RfDvbNetworkId=49722, RfDvbTsid=61236, RfFreqHz=6100000000, RfFreqNo=101, RfInnerFec=3, RfModulation=64, RfNgodS6Name=null, RfOuterFec=7, RfSymPerSec=6400000, SgIngestName=Q1Gob-202} ",

};
static String[] ActualRes = new String[expectedRes.length];
static String myStr;


@BeforeClass
public static void setUpBeforeClass() throws Exception {
mongoClient=new MongoClient("10.85.2.123" , 27017);
db = mongoClient.getDB( "admin" );
auth = db.authenticate("admin", "nagra".toCharArray());
db = mongoClient.getDB("srm");
//System.out.print(auth);
}

@AfterClass
public static void tearDownAfterClass() throws Exception {

mongoClient.close();
}

@Before
public void setUp() throws Exception {
coll = db.getCollection("ServiceGroupResource");
}

@After
public void tearDown() throws Exception {
cursor.close();
}

@SuppressWarnings("deprecation")
@Test
public void test() throws UnknownHostException {
cursor = coll.find();
while(cursor.hasNext()) {
int i = 0;
myDoc = cursor.next();
myDoc.removeField("_id");

ActualRes[i] = myDoc.toMap().toString();
System.out.println("value of" + ActualRes[i]);
// ActualRes[i] = myStr;

i++;
}
assertEquals(expectedRes, ActualRes);
}

}

posted on 2013-03-21 15:05  safinator  阅读(142)  评论(0编辑  收藏  举报

导航