Java Code Examples for org.junit.Before

The following are top voted examples for showing how to use org.junit.Before. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: elasticsearch-osem   File: ElasticSearchOsemIntegrationTest.java View source code 6 votes vote down vote up
@Before
public void setUp() {
    node = nodeBuilder().local(true).node();
    Client client = node.client();
    indexer = new ElasticSearchIndexerImpl(client, "test");
    searcher = new ElasticSearchSearcherImpl(client, "test");
    indexer.deleteIndex();  // delete old index if exist
    indexer.createIndex();
}
 
Example 2
Project: lettuce   File: AtLeastOnceTest.java View source code 6 votes vote down vote up
@Before
public void before() throws Exception {
    client.setOptions(new ClientOptions.Builder().autoReconnect(true).build());

    // needs to be increased on slow systems...perhaps...
    client.setDefaultTimeout(3, TimeUnit.SECONDS);

    RedisConnection<String, String> connection = client.connect();
    connection.flushall();
    connection.flushdb();
    connection.close();
}
 
Example 3
Project: beanoh   File: BeanohTestCase.java View source code 6 votes vote down vote up
/**
 * Clears the ignored class name, package, and duplicate bean names lists
 * before every test.
 */
@Before
public void setUp() {
	ignoredClassNames = new HashSet<String>();
	ignoredPackages = new HashSet<String>();
	ignoredDuplicateBeanNames = new HashSet<String>();
}
 
Example 4
Project: strongback-java   File: CompassTest.java View source code 6 votes vote down vote up
@Override
@Before
public void beforeEach() {
    super.beforeEach();
    setValue(0);
    sensor.zero();
}
 
Example 5
Project: hitchfs   File: MemoryFileSystemTest.java View source code 6 votes vote down vote up
@Before
public void setup() {
	this.fs = new MemoryFileSystem() {
		@Override
		public String getCurrentDirectory() {
			return "/a/b";
		}
		@Override
		public long currentTimeMillis() {
			return 87654;
		}
		@Override
		public boolean isOwner(FakeFile fake) {
			return isOwner.get();
		}
	};
}
 
Example 6
Project: netlib   File: SwitchingAndCachingNetAddressNameServiceLocalTest.java View source code 6 votes vote down vote up
@Before
public void setUp() {
    // prepare and mock1
    Map<String,NetAddress> name2AddressMapping1 = new HashMap<String,NetAddress>();
    Map<NetAddress,String> address2NameMapping1 = new HashMap<NetAddress,String>();
    name2AddressMapping1.put(TEST_HOSTNAME1, TEST_IP1);
    address2NameMapping1.put(TEST_IP1, TEST_HOSTNAME1);
    NetAddressNameService mock1Ns = new MockNetAddressNameService(name2AddressMapping1, address2NameMapping1);
    
    // prepare and mock2
    Map<String,NetAddress> name2AddressMapping2 = new HashMap<String,NetAddress>();
    Map<NetAddress,String> address2NameMapping2 = new HashMap<NetAddress,String>();
    name2AddressMapping2.put(TEST_HOSTNAME2, TEST_IP2);
    address2NameMapping2.put(TEST_IP2, TEST_HOSTNAME2);
    mock2Ns = new MockNetAddressNameService(name2AddressMapping2, address2NameMapping2);
    
    // SwitchingNetAddressNameService on top
    switchingNs = new SwitchingNetAddressNameService(mock1Ns);
    
    // CachingNetAddressNameService on top
    ns = new CachingNetAddressNameService(switchingNs,
            MAX_ELEMENTS_IN_CACHE, IS_NAME_CASE_SENSITIVE,
            CACHE_TTL_SECONDS, CACHE_NEGATIVE_TTL_SECONDS);
}
 
Example 7
Project: jbosgi   File: LayeredBundlePathTest.java View source code 6 votes vote down vote up
@Before
public void setUp() throws Exception {

    reposRoot = new File(getResource(PATH), "repos");
    if (!reposRoot.mkdirs() && !reposRoot.isDirectory()) {
        throw new IllegalStateException("Cannot create reposRoot");
    }
    repoA = new File(reposRoot, "root-a");
    if (!repoA.mkdirs() && !repoA.isDirectory()) {
        throw new IllegalStateException("Cannot create reposA");
    }
    repoB = new File(reposRoot, "root-b");
    if (!repoB.mkdirs() && !repoB.isDirectory()) {
        throw new IllegalStateException("Cannot create reposB");
    }
}
 
Example 8
Project: java-promises   File: PromisesTestCase.java View source code 6 votes vote down vote up
@Before
public void setup() {
  done = new LinkedList<String>();
  failed = new LinkedList<Exception>();
  deferred = new Deferred<Integer>();
  promise = deferred.promise;
  promise.then(Callbacks.<Integer>toStringHandler(), Callbacks.<Exception>toStringHandler()).then(Callbacks.addToHandler(done), Callbacks.addToHandler(failed));
}
 
Example 9
Project: richfaces   File: TestChoicePickerByWebElement.java View source code 6 votes vote down vote up
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);

    List<WebElement> divs = new ArrayList<WebElement>();
    for (int i = 1; i <= 6; i++) {
        WebElement elem = mock(WebElement.class);
        when(elem.getText()).thenReturn("" + i);
        switch(i) {
            case 1 : when(elem.getAttribute("class")).thenReturn("odd first"); break;
            case 2 : when(elem.getAttribute("class")).thenReturn("even second"); break;
            case 3 : when(elem.getAttribute("class")).thenReturn("odd"); break;
            case 4 : when(elem.getAttribute("class")).thenReturn("even"); break;
            case 5 : when(elem.getAttribute("class")).thenReturn("odd"); break;
            case 6 : when(elem.getAttribute("class")).thenReturn("even last"); break;
        }
        divs.add(elem);
    }
    when(myFragment.getDivs()).thenReturn(divs);
}
 
Example 10
Project: jena   File: TestTransRestart.java View source code 6 votes vote down vote up
@Before public void setup() {
    path = ConfigTest.getCleanDir() ; 
    location = Location.create (path) ;
    if ( useTransactionsSetup )
        setupTxn() ;
    else
        setupPlain() ;
}
 
Example 11
Project: wampspring   File: EventMessengerTest.java View source code 6 votes vote down vote up
@Before
public void setup() {
	MockitoAnnotations.initMocks(this);
	Mockito.when(this.brokerChannel.send(Matchers.any(WampMessage.class)))
			.thenReturn(true);
	Mockito.when(this.clientOutboundChannel.send(Matchers.any(WampMessage.class)))
			.thenReturn(true);
	this.eventMessenger = new EventMessenger(this.brokerChannel,
			this.clientOutboundChannel);
}
 
Example 12
Project: sgithub   File: BaseGitHubServiceTest.java View source code 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	super.setUp();
   	assertNotNullOrEmpty(String.format(RESOURCE_MISSING_MESSAGE, "Test Username."), TestConstants.TEST_USER_NAME);
   	assertNotNullOrEmpty(String.format(RESOURCE_MISSING_MESSAGE, "Test API Key."), TestConstants.TEST_API_KEY);
   	authentication = new LoginTokenAuthentication(TestConstants.TEST_USER_NAME, TestConstants.TEST_API_KEY);
	factory = GitHubServiceFactory.newInstance();
	
}
 
Example 13
Project: hdt-java   File: LongArrayTest.java View source code 6 votes vote down vote up
@Before
public void setUp() throws Exception {
	Random r = new Random(1);	

	plain = new long[numentries];
	array = new SequenceInt64(numentries);

	for(int k=0;k<numentries;k++) {
		long value = Math.abs(r.nextLong());
		array.append(value);
		plain[k]=value;
	}
}
 
Example 14
Project: CsvEngine   File: ValidationTest.java View source code 6 votes vote down vote up
/**
 * Construction of streams and engine useful for tests.
 */
@Before
public void setup() {
	streamRule1 = new StringStream("att1,att2\nval1,\n,val2\n,");
	rule1Engine =
			new CsvEngine(EngineParameters.createBuilder().setValidation(true).setNbLinesWithErrorsToStop(999).build(),
					ObjectRule1_1.class, ObjectRule1_2.class, ObjectRule1_3.class, ObjectRule1_4.class);

}
 
Example 15
Project: usc   File: UscPluginTest.java View source code 6 votes vote down vote up
/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    UscConfigurationServiceImpl.setDefaultPropertyFilePath("src/test/resources/etc/usc/usc.properties");
    
    /*Logger root = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    if (root instanceof SimpleLogger) {
        SimpleLogger.setLevel(SimpleLogger.TRACE);
    }*/
    // set up client bootstrap
    clientBootstrap.group(localGroup);
    clientBootstrap.channel(LocalChannel.class);
    clientBootstrap.handler(new ChannelInitializer<LocalChannel>() {
        @Override
        public void initChannel(LocalChannel ch) throws Exception {
            ChannelPipeline p = ch.pipeline();
            p.addLast(new LoggingHandler("UscPluginTest client", LogLevel.TRACE));

            // Decoders
            p.addLast("frameDecoder", new DelimiterBasedFrameDecoder(80, false, Delimiters.lineDelimiter()));
            p.addLast("stringDecoder", new StringDecoder(CharsetUtil.UTF_8));

            // Encoder
            p.addLast("stringEncoder", new StringEncoder(CharsetUtil.UTF_8));

        }
    });

}
 
Example 16
Project: mockjndi   File: TestJNDILookup.java View source code 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    final Hashtable<String, String> environment = new Hashtable<String, String>();
    environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.btmatthews.mockjndi.core.MockInitialContextFactory");
    environment.put("com.btmatthews.mockjndi.config", "classpath:mockjndi.xml");
    rootContext = new InitialContext(environment);
}
 
Example 17
Project: AIDR   File: TestNominalLabelResourceFacadeImp.java View source code 6 votes vote down vote up
@Before
public void setUp() {
	try {
		nominalLabel = new NominalLabelDTO(nominalAttribute, "test_nominal_label_code", "test_nominal_label_name", "test_nominal_label_desc", 500);
	} catch (PropertyNotSetException e) {
		logger.error("PropertyNotSetException while creating object of nominal label "+e.getMessage());
	}
	entityManager.getTransaction().begin();
	nominalLabel = nominalLabelResourceFacadeImp.addNominalLabel(nominalLabel);
	entityManager.getTransaction().commit();
}
 
Example 18
Project: grap   File: HydrologyUtilitiesTest.java View source code 6 votes vote down vote up
@Before
public void setUp() throws Exception {

	demArray = new float[] {//
	ND, ND, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, 99, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 95, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 90, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 85, ND, ND, ND, ND, ND, ND, ND,// 
			ND, 80, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 75, 70, 65, 60, ND, ND, 45, ND,// 
			ND, ND, ND, ND, ND, ND, 55, 50, ND, ND,// 
			ND, ND, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, ND, ND, ND, ND, ND, ND, ND, ND,// 
	};
	RasterMetadata rasterMetadata = new RasterMetadata(0, 15, 1, -1, ncols,
			nrows);
	dem = GeoRasterFactory.createGeoRaster(demArray, rasterMetadata);
	dem.setNodataValue(ND);

	directionArray = new float[] {//
	ND, ND, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, 8, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 7, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 7, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 6, ND, ND, ND, ND, ND, ND, ND,// 
			ND, 8, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 1, 1, 1, 8, ND, ND, -1, ND,// 
			ND, ND, ND, ND, ND, ND, 1, 2, ND, ND, // 
			ND, ND, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, ND, ND, ND, ND, ND, ND, ND, ND,// 
	};
	direction = dem.doOperation(new D8OpDirection());

	accumulation = direction.doOperation(new D8OpAccumulation());
	accumulationArray = new float[] {//
	ND, ND, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, 1, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 2, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 3, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 4, ND, ND, ND, ND, ND, ND, ND,// 
			ND, 5, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, 6, 7, 8, 9, ND, ND, 12, ND,// 
			ND, ND, ND, ND, ND, ND, 10, 11, ND, ND, // 
			ND, ND, ND, ND, ND, ND, ND, ND, ND, ND,// 
			ND, ND, ND, ND, ND, ND, ND, ND, ND, ND,// 
	};
}
 
Example 19
Project: OrganicBuilder   File: ActionConfigurerTest.java View source code 6 votes vote down vote up
@SuppressWarnings({"unchecked", "rawtypes"})
@Before
public void setup() {
    actionConfigurer = ActionConfigurerFactory.createCustomConfigurer(
            properties, messageSource, conversionService,
            Arrays.asList(actionProperty));

    when(actionProperty.getMessageCode(IDENTIFIER))
            .thenReturn(MESSAGE_CODE);
    when(actionProperty.getTargetType()).thenReturn((Class) TARGET_TYPE);
    when(actionProperty.getSwingKey()).thenReturn(SWING_KEY);
}
 
Example 20
Project: java-csp   File: SignTest.java View source code 6 votes vote down vote up
@Before
public void before() throws Exception {
	
	fac = XMLSignatureFactory.getInstance("DOM", CSPXML_PROVIDER);
	compareClasses("XMLSignatureFactory", fac.getClass(), org.company.security.csp.xml.dsig.internal.dom.DOMXMLSignatureFactory.class);
	
	signKeys = new ArrayList<Key>();
	
	KeyStore keyStore = java.security.KeyStore.getInstance(STORE_NAME, CSP_PROVIDER);
	keyStore.load(null, null);
	
	for(Enumeration<String> aliases = keyStore.aliases(); aliases.hasMoreElements(); ) {
		String alias = aliases.nextElement();
		
		Key key = keyStore.getKey(alias, null);
		
		if(key != null) {
			compareClasses("PrivateKey", key.getClass(), org.company.security.csp.CSPPrivateKey.class);
			signKeys.add(key);
		}
	}
}