org.junit.Before Java Examples

The following examples show how to use org.junit.Before. 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 Project: kareldb   Author: rayokota   File: ClusterTestHarness.java    License: Apache License 2.0 7 votes vote down vote up
@Before
public void setUp() throws Exception {
    zookeeper = new EmbeddedZookeeper();
    zkConnect = String.format("localhost:%d", zookeeper.port());

    configs = new Vector<>();
    servers = new Vector<>();
    for (int i = 0; i < numBrokers; i++) {
        KafkaConfig config = getKafkaConfig(i);
        configs.add(config);

        KafkaServer server = TestUtils.createServer(config, Time.SYSTEM);
        servers.add(server);
    }

    String[] serverUrls = new String[servers.size()];
    ListenerName listenerType = ListenerName.forSecurityProtocol(getSecurityProtocol());
    for (int i = 0; i < servers.size(); i++) {
        serverUrls[i] =
            Utils.formatAddress(
                servers.get(i).config().advertisedListeners().head().host(),
                servers.get(i).boundPort(listenerType)
            );
    }
    bootstrapServers = Utils.join(serverUrls, ",");
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: RequestPartIntegrationTests.java    License: MIT License 7 votes vote down vote up
@Before
public void setup() {
	ByteArrayHttpMessageConverter emptyBodyConverter = new ByteArrayHttpMessageConverter();
	emptyBodyConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));

	List<HttpMessageConverter<?>> converters = new ArrayList<>(3);
	converters.add(emptyBodyConverter);
	converters.add(new ByteArrayHttpMessageConverter());
	converters.add(new ResourceHttpMessageConverter());
	converters.add(new MappingJackson2HttpMessageConverter());

	AllEncompassingFormHttpMessageConverter converter = new AllEncompassingFormHttpMessageConverter();
	converter.setPartConverters(converters);

	restTemplate = new RestTemplate(new HttpComponentsClientHttpRequestFactory());
	restTemplate.setMessageConverters(Collections.singletonList(converter));
}
 
Example #3
Source Project: airsonic-advanced   Author: airsonic-advanced   File: StatusServiceTestCase.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Before
public void setUp() {
    doReturn(new MediaFile()).when(mediaFileService).getMediaFile(any(Path.class));
    doReturn(settings).when(settingsService).getUserSettings(any(String.class));
    doReturn(true).when(settings).getNowPlayingAllowed();
    service = new StatusService();
    service.setMessagingTemplate(messagingTemplate);
    service.setMediaFileService(mediaFileService);
    service.setSettingsService(settingsService);
    player1 = new Player();
    player1.setId(1);
    player1.setUsername("p1");
    player2 = new Player();
    player2.setId(2);
    player2.setUsername("p2");
}
 
Example #4
Source Project: flink   Author: flink-tpc-ds   File: SimplifyTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
@Override
public void setup() throws Exception{
	super.setup();

	Object[][] edges = new Object[][]{
		new Object[]{0, 0},
		new Object[]{0, 1},
		new Object[]{0, 1},
		new Object[]{0, 2},
		new Object[]{0, 2},
		new Object[]{1, 0},
		new Object[]{2, 2},
	};

	List<Edge<IntValue, NullValue>> edgeList = new LinkedList<>();

	for (Object[] edge : edges) {
		edgeList.add(new Edge<>(new IntValue((int) edge[0]), new IntValue((int) edge[1]), NullValue.getInstance()));
	}

	graph = Graph.fromCollection(edgeList, env);
}
 
Example #5
Source Project: data-highway   Author: HotelsDotCom   File: PaverServiceImplTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void before() {
  road.setName(ROAD_NAME);
  road.setContactEmail("[email protected]");
  road.setDescription("road description");
  road.setTeamName("awesome team");
  road.setAuthorisation(new Authorisation());
  road.getAuthorisation().setOnramp(new Onramp());
  road.getAuthorisation().getOnramp().setCidrBlocks(emptyList());
  road.getAuthorisation().getOnramp().setAuthorities(emptyList());
  road.getAuthorisation().setOfframp(new Offramp());
  road.getAuthorisation().getOfframp().setAuthorities(emptyMap());
  road.setDeleted(false);
  underTest = new PaverServiceImpl(roadAdminClient, schemaStoreClient, cidrBlockValidator, mappings,
      notificationHandler, true, clock);
}
 
Example #6
Source Project: incubator-weex-playground   Author: apache   File: AG_Switch_Switch_Checked.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws InterruptedException {
	super.setUp();
	TreeMap testMap = new <String, Object> TreeMap();
	testMap.put("testComponet", "AG_Switch");
	testMap.put("testChildCaseInit", "AG_Switch_Switch_Checked");
	testMap.put("step1",new TreeMap(){
		{
			put("click", "true");
			put("screenshot", "AG_Switch_Switch_Checked_01_true");
		}
	});
	testMap.put("step2",new TreeMap(){
		{
			put("click", "false");
			put("screenshot", "AG_Switch_Switch_Checked_02_false");
		}
	});
	super.setTestMap(testMap);
}
 
Example #7
Source Project: hop   Author: project-hop   File: DatabaseJoinTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {

  TransformMeta mockTransformMeta = mock( TransformMeta.class );
  PipelineMeta mockPipelineMeta = mock( PipelineMeta.class );
  Pipeline mockPipeline = mock( Pipeline.class );
  TransformPartitioningMeta mockTransformPartitioningMeta = mock( TransformPartitioningMeta.class );

  when( mockTransformMeta.getName() ).thenReturn( "MockTransform" );
  when( mockPipelineMeta.findTransform( anyString() ) ).thenReturn( mockTransformMeta );
  when( mockTransformMeta.getTargetTransformPartitioningMeta() ).thenReturn( mockTransformPartitioningMeta );

  mockITransform = mock( DatabaseJoinMeta.class, withSettings().extraInterfaces( ITransform.class ) );
  mockTransformDataInterface = mock( DatabaseJoinData.class, withSettings().extraInterfaces( ITransform.class ) );
  mockTransformDataInterface.db = mock( Database.class );
  mockTransformDataInterface.pstmt = mock( PreparedStatement.class );
  mockDatabaseJoin = spy( new DatabaseJoin( mockTransformMeta, mockTransformDataInterface, 1, mockPipelineMeta, mockPipeline ) );
}
 
Example #8
Source Project: hivemq-community-edition   Author: hivemq   File: TlsTcpChannelInitializerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
    MockitoAnnotations.initMocks(this);

    pipeline = new FakeChannelPipeline();

    when(tlsTcpListener.getTls()).thenReturn(tls);
    when(ssl.getSslHandler(any(SocketChannel.class), any(Tls.class))).thenReturn(sslHandler);
    when(sslHandler.handshakeFuture()).thenReturn(future);
    when(socketChannel.pipeline()).thenReturn(pipeline);
    when(socketChannel.attr(any(AttributeKey.class))).thenReturn(attribute);
    when(channelDependencies.getConfigurationService()).thenReturn(fullConfigurationService);

    tlstcpChannelInitializer = new TlsTcpChannelInitializer(channelDependencies, tlsTcpListener, ssl, eventLog);

}
 
Example #9
Source Project: das   Author: ppdaicorp   File: TableDaoShardByDbTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
    for (int i = 0; i < DB_MODE; i++) {
        String[] statements = new String[TABLE_MODE];
        for (int j = 0; j < TABLE_MODE; j++) {
            statements[j] = String.format("INSERT INTO person(PeopleID, Name, CountryID, CityID, ProvinceID) VALUES(%d, 'test', %d, %d, 1)", j + 1, i, j);
        }

        if(!allowInsertWithId())
            statements = DbSetupUtil.handle("Person", statements);

        BatchUpdateBuilder builder = new BatchUpdateBuilder(statements);
        builder.hints().inShard(i);
        super.dao.batchUpdate(builder);
    }
}
 
Example #10
Source Project: hypersistence-optimizer   Author: vladmihalcea   File: SpringJpaXmlTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    try {
        transactionTemplate.execute((TransactionCallback<Void>) transactionStatus -> {
            Tag hibernate = new Tag();
            hibernate.setName("hibernate");
            entityManager.persist(hibernate);

            Tag jpa = new Tag();
            jpa.setName("jpa");
            entityManager.persist(jpa);
            return null;
        });
    } catch (TransactionException e) {
        LOGGER.error("Failure", e);
    }

}
 
Example #11
Source Project: hop   Author: project-hop   File: BlockUntilStepsFinishMetaTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUpLoadSave() throws Exception {
  PluginRegistry.init( false );
  List<String> attributes =
    Arrays.asList( "transformName", "transformCopyNr" );

  Map<String, String> getterMap = new HashMap<>();
  Map<String, String> setterMap = new HashMap<>();
  FieldLoadSaveValidator<String[]> stringArrayLoadSaveValidator =
    new ArrayLoadSaveValidator<String>( new StringLoadSaveValidator(), 5 );

  Map<String, FieldLoadSaveValidator<?>> attrValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();
  attrValidatorMap.put( "transformName", stringArrayLoadSaveValidator );
  attrValidatorMap.put( "transformCopyNr", stringArrayLoadSaveValidator );

  Map<String, FieldLoadSaveValidator<?>> typeValidatorMap = new HashMap<String, FieldLoadSaveValidator<?>>();

  loadSaveTester =
    new LoadSaveTester<>( testMetaClass, attributes, new ArrayList<>(),
      getterMap, setterMap, attrValidatorMap, typeValidatorMap, this );
}
 
Example #12
Source Project: flink   Author: flink-tpc-ds   File: IncrementalSSSPITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws Exception {
	resultPath = tempFolder.newFile().toURI().toString();
	File verticesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(verticesFile, IncrementalSSSPData.VERTICES);

	File edgesFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesFile, IncrementalSSSPData.EDGES);

	File edgesInSSSPFile = tempFolder.newFile();
	FileUtils.writeFileUtf8(edgesInSSSPFile, IncrementalSSSPData.EDGES_IN_SSSP);

	verticesPath = verticesFile.toURI().toString();
	edgesPath = edgesFile.toURI().toString();
	edgesInSSSPPath = edgesInSSSPFile.toURI().toString();
}
 
Example #13
Source Project: Tomcat8-Source-Read   Author: chenmudu   File: TestContextName.java    License: MIT License 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    cn1 = new ContextName(null, null);
    cn2 = new ContextName("", null);
    cn3 = new ContextName("/", null);
    cn4 = new ContextName("/foo", null);
    cn5 = new ContextName("/foo/bar", null);
    cn6 = new ContextName(null, "A");
    cn7 = new ContextName("", "B");
    cn8 = new ContextName("/", "C");
    cn9 = new ContextName("/foo", "D");
    cn10 = new ContextName("/foo/bar", "E");
    cn11 = new ContextName("ROOT", false);
    cn12 = new ContextName("foo", false);
    cn13 = new ContextName("foo#bar", false);
    cn14 = new ContextName("ROOT##A", false);
    cn15 = new ContextName("foo##D", false);
    cn16 = new ContextName("foo#bar##E", false);
    cn17 = new ContextName("/ROOT", null);
    cn18 = new ContextName("/ROOT#bar", false);
    cn19 = new ContextName("/ROOT#bar##A", false);
    cn20 = new ContextName("/ROOT##A", false);
    cn21 = new ContextName("foo.war", false);
    cn22 = new ContextName("foo.war", true);
}
 
Example #14
Source Project: NeurophFramework   Author: neuroph   File: AndTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() {
    instance = new And();
    inputNeurons = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        inputNeurons.add(new InputNeuron());
    }
           
    Neuron toNeuron = new Neuron();

    inputConnections = new ArrayList<>();
    for (int i = 0; i < 4; i++) {
        inputConnections.add(new Connection(inputNeurons.get(i), toNeuron, 1));
        toNeuron.addInputConnection(inputConnections.get(i));
    }
}
 
Example #15
Source Project: aws-athena-query-federation   Author: awslabs   File: RedisMetadataHandlerTest.java    License: Apache License 2.0 6 votes vote down vote up
@Before
public void setUp()
        throws Exception
{
    logger.info("{}: enter", testName.getMethodName());

    when(mockFactory.getOrCreateConn(eq(decodedEndpoint))).thenReturn(mockClient);

    handler = new RedisMetadataHandler(mockGlue, new LocalKeyFactory(), mockSecretsManager, mockAthena, mockFactory, "bucket", "prefix");
    allocator = new BlockAllocatorImpl();

    when(mockSecretsManager.getSecretValue(any(GetSecretValueRequest.class)))
            .thenAnswer((InvocationOnMock invocation) -> {
                GetSecretValueRequest request = invocation.getArgumentAt(0, GetSecretValueRequest.class);
                if ("endpoint".equalsIgnoreCase(request.getSecretId())) {
                    return new GetSecretValueResult().withSecretString(decodedEndpoint);
                }
                throw new RuntimeException("Unknown secret " + request.getSecretId());
            });
}
 
Example #16
Source Project: besu   Author: hyperledger   File: RevertOperationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  when(messageFrame.popStackItem())
      .thenReturn(Bytes32.fromHexString("0x00"))
      .thenReturn(Bytes32.fromHexString("0x0e"));
  when(messageFrame.readMemory(UInt256.ZERO, UInt256.valueOf(0x0e)))
      .thenReturn(revertReasonBytes);
}
 
Example #17
Source Project: vertx-spring-boot   Author: snowdrop   File: VertxServerHttpResponseTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    given(mockRoutingContext.response()).willReturn(mockHttpServerResponse);
    given(mockHttpServerResponse.headers()).willReturn(new VertxHttpHeaders());

    bufferConverter = new BufferConverter();
    response = new VertxServerHttpResponse(mockRoutingContext, bufferConverter);
}
 
Example #18
Source Project: huobi_Java   Author: HuobiRDCenter   File: TestGetOpenOrders.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void Initialize() {
  impl = new RestApiRequestImpl("12345", "67890", new RequestOptions());
  testAccount1.setType(AccountType.SPOT);
  testAccount1.setId(123L);
  testAccount2.setType(AccountType.MARGIN);
  testAccount2.setId(456L);
  List<Account> accountList = new LinkedList<>();
  accountList.add(testAccount1);
  accountList.add(testAccount2);
  testUser.setAccounts(accountList);
}
 
Example #19
Source Project: rocketmq-4.3.0   Author: tianheframe   File: NormalMsgTwoSameGroupConsumerIT.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    printSeperator();
    topic = initTopic();
    logger.info(String.format("use topic: %s;", topic));
    producer = getProducer(nsAddr, topic);
}
 
Example #20
Source Project: hop   Author: project-hop   File: ExcelInputMetaTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  HopEnvironment.init();

  meta = new ExcelInputMeta();
  meta.setFileName( new String[] { "1", "2", "3" } );
  meta.setSheetName( new String[] { "1", "2", "3", "4" } );
  meta.setField( new ExcelInputField[] {
    new ExcelInputField( "1", 1, 1 ),
    new ExcelInputField( "2", 2, 2 ) } );
  meta.normilizeAllocation();
}
 
Example #21
Source Project: Moss   Author: SpringCloud   File: AdminApplicationDiscoveryTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    instance = new SpringApplicationBuilder().sources(TestAdminApplication.class)
                                             .web(WebApplicationType.REACTIVE)
                                             .run("--server.port=0", "--management.endpoints.web.base-path=/mgmt",
                                                 "--endpoints.health.enabled=true", "--info.test=foobar",
                                                 "--eureka.client.enabled=false");

    simpleDiscovery = instance.getBean(SimpleDiscoveryProperties.class);

    this.port = instance.getEnvironment().getProperty("local.server.port", Integer.class, 0);
    this.webClient = createWebClient(this.port);
}
 
Example #22
Source Project: ghidra   Author: NationalSecurityAgency   File: DefinedDataIteratorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

	builder = new ToyProgramBuilder("DefinedDataIteratorTests", false);
	program = builder.getProgram();
	dtm = program.getDataTypeManager();

	intDT = AbstractIntegerDataType.getSignedDataType(4, dtm);
	intTD = new TypedefDataType("int_typedef", intDT);
	stringDT = StringDataType.dataType;
	charDT = new CharDataType(dtm);
	charArray = new ArrayDataType(charDT, 20, charDT.getLength());

	struct1DT = new StructureDataType("struct1", 100);
	struct1DT.replaceAtOffset(0, intDT, intDT.getLength(), "f1", null);
	struct1DT.replaceAtOffset(10, charArray, charArray.getLength(), "f2", null);
	struct1DT.replaceAtOffset(50, stringDT, 10, "f3", null);

	structArray = new ArrayDataType(struct1DT, 10, struct1DT.getLength());

	struct2DT = new StructureDataType("struct2", 200);
	struct2DT.replaceAtOffset(0, intDT, intDT.getLength(), "f1", null);
	struct2DT.replaceAtOffset(10, struct1DT, intDT.getLength(), "f2", null);

	builder.createMemory("test", "0x0", 0x2000);
	program = builder.getProgram();
}
 
Example #23
Source Project: java-technology-stack   Author: codeEngraver   File: NameMatchMethodPointcutTests.java    License: MIT License 5 votes vote down vote up
/**
 * Create an empty pointcut, populating instance variables.
 */
@Before
public void setup() {
	ProxyFactory pf = new ProxyFactory(new SerializablePerson());
	nop = new SerializableNopInterceptor();
	pc = new NameMatchMethodPointcut();
	pf.addAdvisor(new DefaultPointcutAdvisor(pc, nop));
	proxied = (Person) pf.getProxy();
}
 
Example #24
Source Project: aws-athena-query-federation   Author: awslabs   File: TypedSerDeTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void before()
{
    allocator = new BlockAllocatorImpl("test-allocator-id");
    mapper = VersionedObjectMapperFactory.create(allocator);
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
}
 
Example #25
Source Project: hop   Author: project-hop   File: WorkflowEntryWriteToLogTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  parentWorkflow = mock( Workflow.class );
  doReturn( false ).when( parentWorkflow ).isStopped();

  action = new ActionWriteToLog();
  action = spy( action );
}
 
Example #26
Source Project: hadoop-ozone   Author: apache   File: TestObjectHead.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws IOException {
  //Create client stub and object store stub.
  OzoneClient clientStub = new OzoneClientStub();

  // Create volume and bucket
  clientStub.getObjectStore().createS3Bucket(bucketName);

  bucket = clientStub.getObjectStore().getS3Bucket(bucketName);

  // Create HeadBucket and setClient to OzoneClientStub
  keyEndpoint = new ObjectEndpoint();
  keyEndpoint.setClient(clientStub);
}
 
Example #27
Source Project: mr-hashemi   Author: mr-hashemi   File: PassItselfBackViaContextTest.java    License: Universal Permissive License v1.0 5 votes vote down vote up
@Before
public void prepareSystem() {
    myObj = new MyObj();
    context = Context.newBuilder().allowPolyglotAccess(PolyglotAccess.ALL).build();
    context.getPolyglotBindings().putMember("myObj", myObj);
    context.eval("hashemi", "bebin azinja() {\n" + "  bede import(\"myObj\");\n" + "}\n");
    myObjWrapped = context.getBindings("hashemi").getMember("azinja").execute();
    assertFalse(myObjWrapped.isNull());
    myObjCall = myObjWrapped.as(CallWithValue.class);
}
 
Example #28
Source Project: hop   Author: project-hop   File: CloneRowTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
  transformMockHelper =
    new TransformMockHelper<CloneRowMeta, CloneRowData>( "Test CloneRow", CloneRowMeta.class, CloneRowData.class );
  when( transformMockHelper.logChannelFactory.create( any(), any( ILoggingObject.class ) ) )
    .thenReturn( transformMockHelper.logChannelInterface );
  when( transformMockHelper.pipeline.isRunning() ).thenReturn( true );
}
 
Example #29
Source Project: arcusplatform   Author: arcus-smart-home   File: TestGroovyDriverPlatformHandlers.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@Before
public void setUp() throws Exception {
   super.setUp();
   driver = factory.load(driverFile);
   context = new PlatformDeviceDriverContext(createDevice(driver), driver, mockPopulationCacheMgr);
}
 
Example #30
Source Project: besu   Author: hyperledger   File: RewardTraceGeneratorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  final BlockBody blockBody = new BlockBody(Collections.emptyList(), List.of(ommerHeader));
  final BlockHeader blockHeader =
      gen.header(0x0A, blockBody, new BlockDataGenerator.BlockOptions());
  block = new Block(blockHeader, blockBody);
  when(protocolSchedule.getByBlockNumber(block.getHeader().getNumber())).thenReturn(protocolSpec);
  when(protocolSpec.getBlockReward()).thenReturn(blockReward);
  when(protocolSpec.getMiningBeneficiaryCalculator()).thenReturn(miningBeneficiaryCalculator);
  when(miningBeneficiaryCalculator.calculateBeneficiary(block.getHeader()))
      .thenReturn(blockBeneficiary);
  when(miningBeneficiaryCalculator.calculateBeneficiary(ommerHeader))
      .thenReturn(ommerBeneficiary);
}