Java Code Examples for org.easymock.EasyMock#expectLastCall()

The following examples show how to use org.easymock.EasyMock#expectLastCall() . 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 File: FederationLogoutTest.java    From cxf-fediz with Apache License 2.0 6 votes vote down vote up
@org.junit.Test
public void testSignoutCustomQueryParameter() throws Exception {
    FedizContext config = getFederationConfigurator().getFedizContext("ROOT3");

    HttpServletRequest req = EasyMock.createMock(HttpServletRequest.class);
    EasyMock.expect(req.getParameter(FederationConstants.PARAM_ACTION)).andReturn(null).anyTimes();
    EasyMock.expect(req.getParameter(FederationConstants.PARAM_REPLY)).andReturn(null);
    EasyMock.expect(req.getParameter("SAMLResponse")).andReturn(null);
    EasyMock.expect(req.getRequestURL()).andReturn(new StringBuffer(LOGOUT_URL));
    EasyMock.expect(req.getRequestURI()).andReturn(LOGOUT_URI);
    EasyMock.expect(req.getContextPath()).andReturn(LOGOUT_URI);
    EasyMock.replay(req);

    LogoutHandler logoutHandler = new LogoutHandler(config);
    Assert.assertTrue(logoutHandler.canHandleRequest(req));

    HttpServletResponse resp = EasyMock.createMock(HttpServletResponse.class);
    String expectedRedirectToIdP =
        "http://url_to_the_issuer?wa=wsignout1.0&wreply=https%3A%2F%2Flocalhost%2Fsecure%2Flogout%2Findex.html"
        + "&wtrealm=target+realm&custom=param";
    resp.sendRedirect(expectedRedirectToIdP);
    EasyMock.expectLastCall();
    EasyMock.replay(resp);
    logoutHandler.handleRequest(req, resp);
}
 
Example 2
Source File: TestBasicNotificationStrategy.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleTriggersOfSameTypeOnlyIssueOneNotification() {
   Capture<CallTreeContext> contextCapture = EasyMock.newCapture(CaptureType.ALL);
   callTreeExecutor.notifyOwner(EasyMock.capture(contextCapture));
   EasyMock.expectLastCall();

   setupCallTree(1, callTreeEntry(UUID.randomUUID(), true));
   Trigger t = setupTrigger(UUID.randomUUID(), AlertType.CO, "Some Device", "Some Dev Type Hint", 1);
   Trigger t2 = setupTrigger(UUID.randomUUID(), AlertType.CO, "Some Device", "Some Dev Type Hint", 0);

   replay();

   AlarmIncident incident = incidentBuilder()
         .withAlert(AlertType.CO)
         .build();

   strategy.execute(incident.getAddress(), incident.getPlaceId(), ImmutableList.of(t, t2));
   List<CallTreeContext> contexts = contextCapture.getValues();
   assertEquals(1, contexts.size());
   assertCallTreeContext(contexts.get(0), NotificationConstants.CO_KEY, NotificationCapability.NotifyRequest.PRIORITY_CRITICAL);
   verify();
}
 
Example 3
Source File: TestModelStore.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveObjectListener() {
   Capture<RuleEvent> eventRef = EasyMock.newCapture();
   Consumer<RuleEvent> listener = EasyMock.createMock(Consumer.class);
   listener.accept(EasyMock.capture(eventRef));
   EasyMock.expectLastCall();
   EasyMock.replay(listener);

   MessageBody body =
         MessageBody
            .buildMessage(Capability.EVENT_DELETED, ImmutableMap.of());
   PlatformMessage message = PlatformMessage.createBroadcast(body, address);
   
   RuleModelStore store = new RuleModelStore();
   store.addModel(ImmutableList.of(attributes));
   store.addListener(listener);
   store.update(message);
   
   ModelRemovedEvent event = (ModelRemovedEvent) eventRef.getValue();
   assertEquals(RuleEventType.MODEL_REMOVED, event.getType());
   assertEquals(address, event.getModel().getAddress());
   assertEquals(id, event.getModel().getAttribute(Capability.ATTR_ID));
   assertEquals(DeviceCapability.NAMESPACE, event.getModel().getAttribute(Capability.ATTR_TYPE));
   
   EasyMock.verify(listener);
}
 
Example 4
Source File: AuditServiceImplTest.java    From Asqatasun with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Test of audit method, of class AuditServiceImpl.
 */
public void testAudit() {
    AuditServiceImpl instance = initialiseAuditService();
    
    Audit audit = EasyMock.createMock(Audit.class);
    Audit auditReturnedByAuditMethodOfAuditServiceThread = 
            EasyMock.createMock(Audit.class);
    
    AuditServiceThread mockAuditServiceThread = EasyMock.createMock(AuditServiceThread.class);
    
    mockAuditServiceThread.run();
    EasyMock.expectLastCall();
    EasyMock.expect(mockAuditServiceThread.getAudit()).
            andReturn(auditReturnedByAuditMethodOfAuditServiceThread).anyTimes();
    EasyMock.replay(mockAuditServiceThread);
    
    EasyMock.expect(mockAuditServiceThreadFactory.create(audit)).
            andReturn(mockAuditServiceThread).anyTimes();
    EasyMock.replay(mockAuditServiceThreadFactory);
    
    assertEquals(auditReturnedByAuditMethodOfAuditServiceThread, 
            instance.audit(audit));
    
    EasyMock.verify(mockAuditServiceThread);
    EasyMock.verify(mockAuditServiceThreadFactory);
}
 
Example 5
Source File: TestActionList.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
@Test
public void testSingleEntry() throws Exception {
   Action firstAction = EasyMock.createMock(Action.class);
   EasyMock.expect(firstAction.getDescription()).andReturn("mock doing something").anyTimes();
   firstAction.execute(context);
   EasyMock.expectLastCall();
   EasyMock.replay(firstAction);
   
   ActionList action = 
         Actions
            .buildActionList()
            .addAction(firstAction)
            .build();
   
   assertEquals(ActionList.NAME, action.getName());
   assertEquals("first (mock doing something)", action.getDescription());
   action.execute(context);
   
   EasyMock.verify(firstAction);
}
 
Example 6
Source File: TestAbstractTextInterfaceDevice.java    From java-license-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void testPrintOut03()
{
    this.outputStream.print("hello");
    EasyMock.expectLastCall();

    EasyMock.replay(this.device, this.inputStream, this.outputStream, this.errorStream);

    this.device.printOut("hello");
}
 
Example 7
Source File: TestPersonDeleteHandler.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
private void setupSuccessfulDelete(Account account) {
   EasyMock.expect(authGrantDaoMock.findForEntity(person.getId())).andReturn(Arrays.asList(grant));
   EasyMock.expect(accountDaoMock.findById(person.getAccountId())).andReturn(account);
   personDaoMock.delete(person);
   EasyMock.expectLastCall();
   authGrantDaoMock.removeGrantsForEntity(person.getId());
   EasyMock.expectLastCall();
   EasyMock.expect(personDaoMock.findByAddress(Address.fromString(person.getAddress()))).andReturn(person);
   replay();
}
 
Example 8
Source File: ProtocolTrackerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testLifecycle() throws Exception {
   IMocksControl c = EasyMock.createControl();
   BundleContext context = c.createMock(BundleContext.class);
   String[] requiredProtocols = {"a", "b"};
   ServerTrackerCallBack callback = c.createMock(ServerTrackerCallBack.class);

   RefFact protA = new RefFact(c, context, new String[]{"a"});
   RefFact protB = new RefFact(c, context, new String[]{"b"});

   callback.addFactory(protA.factory);
   EasyMock.expectLastCall();

   callback.addFactory(protB.factory);
   EasyMock.expectLastCall();
   callback.start();
   EasyMock.expectLastCall();

   callback.removeFactory(protA.factory);
   EasyMock.expectLastCall();
   callback.stop();
   EasyMock.expectLastCall();

   c.replay();
   ProtocolTracker tracker = new ProtocolTracker("test", context, requiredProtocols, callback);
   tracker.addingService(protA.ref);
   tracker.addingService(protB.ref);
   tracker.removedService(protA.ref, protA.factory);
   c.verify();
}
 
Example 9
Source File: GenericManagerImplTest.java    From ankush with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Test(expected = EntityNotFoundException.class)
   public void testRemove() {
genericDao.remove(1L);
EasyMock.expectLastCall();
EasyMock.expect(genericDao.get(1L)).andThrow(new EntityNotFoundException());
EasyMock.replay(genericDao);

genericManager.remove(1L);
genericManager.get(1L);
   }
 
Example 10
Source File: MemcacheClientWrapperTest.java    From simple-spring-memcached with MIT License 5 votes vote down vote up
@Test
public void shutdown() {
    client.shutdown();
    EasyMock.expectLastCall();
    EasyMock.replay(client);
    clientWrapper.shutdown();
    EasyMock.verify(client);
}
 
Example 11
Source File: AsyncProducerTest.java    From luxun with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueueTimeExpired() throws Exception {
	SyncProducer basicProducer = EasyMock.createMock(SyncProducer.class);
	List<Message> messages = new ArrayList<Message>();
	messages.add(message1);
	List<ProduceRequest> produceRequests = new ArrayList<ProduceRequest>();
	produceRequests.add(new ProduceRequest(this.getMessageListOfSize(messages, 3).toThriftBuffer(), topic1));
	basicProducer.multiSend((List<ProduceRequest>) colEq(produceRequests));
	EasyMock.expectLastCall();
	basicProducer.close();
	EasyMock.expectLastCall();
	EasyMock.replay(basicProducer);
	
	Properties props = new Properties();
    props.put("host", "127.0.0.1");
    props.put("port", "9092");
    props.put("queue.size", "10");
    props.put("serializer.class", "com.leansoft.luxun.serializer.StringEncoder");
    props.put("queue.time", "200");
    props.put("broker.list", TestUtils.brokerList);
    AsyncProducerConfig config = new AsyncProducerConfig(props);
    
    AsyncProducer<String> producer = new AsyncProducer<String>(config, basicProducer, new StringEncoder(), null, null, null, null);
    
    producer.start();
   	for(int i = 0; i < 3; i++) {
   		producer.send(topic1, messageContent1);
   	}
   	
   	Thread.sleep(300);
   	producer.close();
   	EasyMock.verify(basicProducer);
}
 
Example 12
Source File: PolicyVerificationInInterceptorTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testHandleMessage() throws NoSuchMethodException {

    control.reset();
    Method m = AbstractPolicyInterceptor.class.getDeclaredMethod("getTransportAssertions",
        new Class[] {Message.class});
    PolicyVerificationInInterceptor interceptor =
        EasyMock.createMockBuilder(PolicyVerificationInInterceptor.class)
            .addMockedMethod(m).createMock(control);
    setupMessage(true, true, true, true);
    EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE);
    interceptor.getTransportAssertions(message);
    EasyMock.expectLastCall();
    EffectivePolicy effectivePolicy = control.createMock(EffectivePolicy.class);
    EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.TRUE);
    EasyMock.expect(engine.getEffectiveClientResponsePolicy(ei, boi, message)).andReturn(effectivePolicy);
    Policy policy = control.createMock(Policy.class);
    EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
    aim.checkEffectivePolicy(policy);
    EasyMock.expectLastCall().andReturn(null);
    control.replay();
    interceptor.handleMessage(message);
    control.verify();

    control.reset();
    setupMessage(true, true, true, true);
    EasyMock.expect(message.get(Message.PARTIAL_RESPONSE_MESSAGE)).andReturn(Boolean.FALSE);
    interceptor.getTransportAssertions(message);
    EasyMock.expectLastCall();
    effectivePolicy = control.createMock(EffectivePolicy.class);
    EasyMock.expect(message.get(Message.REQUESTOR_ROLE)).andReturn(Boolean.FALSE);
    EasyMock.expect(engine.getEffectiveServerRequestPolicy(ei, boi, message)).andReturn(effectivePolicy);
    policy = control.createMock(Policy.class);
    EasyMock.expect(effectivePolicy.getPolicy()).andReturn(policy);
    aim.checkEffectivePolicy(policy);
    EasyMock.expectLastCall().andReturn(null);
    control.replay();
    interceptor.handleMessage(message);
    control.verify();
}
 
Example 13
Source File: TestLicenseManager.java    From java-license-manager with Apache License 2.0 5 votes vote down vote up
@Test
public void testHasLicenseForAllFeatures04()
{
    License license = this.setupLicenseMocking("LICENSE-ALL-4");
    TestLicenseManager.licenseValidator.validateLicense(license);
    EasyMock.expectLastCall();
    TestLicenseManager.control.replay();

    assertFalse(
        "The returned value is not correct.",
        this.manager.hasLicenseForAllFeatures("LICENSE-ALL-4", "feature#6")
    );
}
 
Example 14
Source File: TestRevokeHandler.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemovedViaAccess() {
   EasyMock.expect(mockDao.getPersonWithRefresh("app1", token)).andReturn(null);
   EasyMock.expect(mockDao.getPersonWithAccess("app1", token)).andReturn(new ImmutablePair<>(person, (int) TimeUnit.DAYS.toSeconds(5)));
   EasyMock.expect(mockDao.getAttrs("app1", person)).andReturn(ImmutableMap.of()).anyTimes();
   mockDao.removePersonAndTokens("app1", person);
   EasyMock.expectLastCall();
   replay();
   FullHttpResponse response = handler.doRevoke(AUTH_HEADER, token);
   assertEquals(HttpResponseStatus.OK, response.getStatus());
   verify();
}
 
Example 15
Source File: FileDbTest.java    From MOE with Apache License 2.0 5 votes vote down vote up
public void testWriteDbToFile() throws Exception {
  IMocksControl control = EasyMock.createControl();
  FileSystem filesystem = control.createMock(FileSystem.class);
  File dbFile = new File("/path/to/db");
  String dbText = "{\n  \"equivalences\": [],\n  \"migrations\": []\n}\n";
  DbStorage dbStorage = GSON.fromJson(dbText, DbStorage.class);
  Db db = new FileDb(dbFile.getPath(), dbStorage, new FileDb.Writer(GSON, filesystem));
  filesystem.write(dbText, dbFile);
  EasyMock.expectLastCall();
  control.replay();
  db.write();
  control.verify();
}
 
Example 16
Source File: TestRestCsrfPreventionFilter.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testGetFetchRequestSessionNoNonce() throws Exception {
    setRequestExpectations(GET_METHOD, session, Constants.CSRF_REST_NONCE_HEADER_FETCH_VALUE);
    EasyMock.expect(session.getAttribute(Constants.CSRF_REST_NONCE_SESSION_ATTR_NAME))
            .andReturn(null);
    session.setAttribute(Constants.CSRF_REST_NONCE_SESSION_ATTR_NAME, NONCE);
    EasyMock.expectLastCall();
    EasyMock.replay(session);
    filter.doFilter(request, response, filterChain);
    verifyContinueChainNonceAvailable();
    EasyMock.verify(session);
}
 
Example 17
Source File: KinesisConnectorRecordProcessorTests.java    From amazon-kinesis-connectors with Apache License 2.0 4 votes vote down vote up
/**
 * Test fail called when all retries done.
 */
@Test
public void testFailAfterRetryLimitReached() throws IOException, KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
    // Test Variables
    Object dummyRecord1 = new Object();
    Object dummyRecord2= new Object();
    List<Object> objectsAsList = new ArrayList<Object>();
    objectsAsList.add(dummyRecord1);
    objectsAsList.add(dummyRecord2);

    List<Object> singleObjectAsList = new ArrayList<Object>();
    singleObjectAsList.add(dummyRecord1);
    String shardId = "shardId";

    Properties props = new Properties();
    // set backoff interval to 0 to speed up test
    props.setProperty(KinesisConnectorConfiguration.PROP_BACKOFF_INTERVAL, String.valueOf(0));
    // set retry limit to allow for retry below (1)
    props.setProperty(KinesisConnectorConfiguration.PROP_RETRY_LIMIT, String.valueOf(1));
    configuration = new KinesisConnectorConfiguration(props, new DefaultAWSCredentialsProviderChain());

    // reset the control to mock new behavior
    control.reset();

    // set expectations for each record
    EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord1);
    EasyMock.expect(filter.keepRecord(dummyRecord1)).andReturn(true);
    buffer.consumeRecord(dummyRecord1, DEFAULT_RECORD_BYTE_SIZE, DEFAULT_SEQUENCE_NUMBER);

    EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord2);
    EasyMock.expect(filter.keepRecord(dummyRecord2)).andReturn(true);
    buffer.consumeRecord(dummyRecord2, DEFAULT_RECORD_BYTE_SIZE, DEFAULT_SEQUENCE_NUMBER);

    EasyMock.expect(buffer.shouldFlush()).andReturn(true);

    // call Buffer.getRecords
    EasyMock.expect(buffer.getRecords()).andReturn(objectsAsList);

    // Transform back
    EasyMock.expect(transformer.fromClass(dummyRecord1)).andReturn(dummyRecord1);
    EasyMock.expect(transformer.fromClass(dummyRecord2)).andReturn(dummyRecord2);

    // Emitter behavior:
    // one call to emit which fails (test a transient issue), and then returns empty on second call

    // uses the original list (i.e. emitItems)
    UnmodifiableBuffer<Object> unmodBuffer = new UnmodifiableBuffer<>(buffer, objectsAsList);
    EasyMock.expect(emitter.emit(EasyMock.eq(unmodBuffer))).andReturn(singleObjectAsList);

    // only one retry, so now we should expect fail to be called.
    emitter.fail(singleObjectAsList);

    // Done, so expect buffer clear and checkpoint
    buffer.getLastSequenceNumber();
    EasyMock.expectLastCall().andReturn(DEFAULT_SEQUENCE_NUMBER);
    buffer.clear();
    EasyMock.expectLastCall();
    checkpointer.checkpoint(DEFAULT_SEQUENCE_NUMBER);
    EasyMock.expectLastCall();

    // Initialize class under test
    KinesisConnectorRecordProcessor<Object, Object> kcrp = new KinesisConnectorRecordProcessor<Object, Object>(
            buffer, filter, emitter, transformer, configuration);
    kcrp.initialize(shardId);

    // Prepare controller for method call
    control.replay();

    // call method
    kcrp.processRecords(getDummyRecordList(objectsAsList.size()), checkpointer);

    control.verify();
}
 
Example 18
Source File: KinesisConnectorRecordProcessorTests.java    From amazon-kinesis-connectors with Apache License 2.0 4 votes vote down vote up
/**
 * Test retry logic only retries unprocessed/failed records
 */
@Test
public void testRetryBehavior() throws IOException, KinesisClientLibDependencyException, InvalidStateException, ThrottlingException, ShutdownException {
    // Test Variables
    Object dummyRecord1 = new Object();
    Object dummyRecord2= new Object();
    List<Object> objectsAsList = new ArrayList<Object>();
    objectsAsList.add(dummyRecord1);
    objectsAsList.add(dummyRecord2);

    List<Object> singleObjectAsList = new ArrayList<Object>();
    singleObjectAsList.add(dummyRecord1);
    String shardId = "shardId";

    Properties props = new Properties();
    // set backoff interval to 0 to speed up test
    props.setProperty(KinesisConnectorConfiguration.PROP_BACKOFF_INTERVAL, String.valueOf(0));
    // set retry limit to allow for retry below
    props.setProperty(KinesisConnectorConfiguration.PROP_RETRY_LIMIT, String.valueOf(2));
    configuration = new KinesisConnectorConfiguration(props, new DefaultAWSCredentialsProviderChain());

    // reset the control to mock new behavior
    control.reset();

    // set expectations for each record
    EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord1);
    EasyMock.expect(filter.keepRecord(dummyRecord1)).andReturn(true);
    buffer.consumeRecord(dummyRecord1, DEFAULT_RECORD_BYTE_SIZE, DEFAULT_SEQUENCE_NUMBER);

    EasyMock.expect(transformer.toClass(EasyMock.anyObject(Record.class))).andReturn(dummyRecord2);
    EasyMock.expect(filter.keepRecord(dummyRecord2)).andReturn(true);
    buffer.consumeRecord(dummyRecord2, DEFAULT_RECORD_BYTE_SIZE, DEFAULT_SEQUENCE_NUMBER);

    EasyMock.expect(buffer.shouldFlush()).andReturn(true);

    // call Buffer.getRecords
    EasyMock.expect(buffer.getRecords()).andReturn(objectsAsList);

    // Transform back
    EasyMock.expect(transformer.fromClass(dummyRecord1)).andReturn(dummyRecord1);
    EasyMock.expect(transformer.fromClass(dummyRecord2)).andReturn(dummyRecord2);

    // Emitter behavior:
    // one call to emit which fails (test a transient issue), and then returns empty on second call

    // uses the original list (i.e. emitItems)
    UnmodifiableBuffer<Object> unmodBuffer = new UnmodifiableBuffer<>(buffer, objectsAsList);
    EasyMock.expect(emitter.emit(EasyMock.eq(unmodBuffer))).andReturn(singleObjectAsList);
    // uses the returned list (i.e. unprocessed)
    unmodBuffer = new UnmodifiableBuffer<>(buffer, singleObjectAsList);
    EasyMock.expect(emitter.emit(EasyMock.eq(unmodBuffer))).andReturn(Collections.emptyList());

    // Done, so expect buffer clear and checkpoint
    buffer.getLastSequenceNumber();
    EasyMock.expectLastCall().andReturn(DEFAULT_SEQUENCE_NUMBER);
    buffer.clear();
    EasyMock.expectLastCall();
    checkpointer.checkpoint(DEFAULT_SEQUENCE_NUMBER);
    EasyMock.expectLastCall();

    // Initialize class under test
    KinesisConnectorRecordProcessor<Object, Object> kcrp = new KinesisConnectorRecordProcessor<Object, Object>(
            buffer, filter, emitter, transformer, configuration);
    kcrp.initialize(shardId);

    // Prepare controller for method call
    control.replay();

    // call method
    kcrp.processRecords(getDummyRecordList(objectsAsList.size()), checkpointer);

    control.verify();
}
 
Example 19
Source File: TestConsoleRSAKeyPairGenerator.java    From java-license-manager with Apache License 2.0 4 votes vote down vote up
@Test
public void testProcessCommandLineOptions02()
{
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    PrintStream printer = new PrintStream(stream);

    this.device.printErrLn("Missing required options: private, public, password");
    EasyMock.expectLastCall();
    EasyMock.expect(this.device.out()).andReturn(printer);
    this.device.exit(1);
    EasyMock.expectLastCall();

    EasyMock.replay(this.generator, this.device);

    this.console.processCommandLineOptions(new String[] {});

    String output = stream.toString();

    assertNotNull("There should be output.", output);
    assertTrue("The output should have length.", output.length() > 0);
    assertEquals(
        "The output is not correct.",
        "usage:  ConsoleRSAKeyPairGenerator -help" + LF +
        " ConsoleRSAKeyPairGenerator -interactive" + LF +
        " ConsoleRSAKeyPairGenerator -password <password> -private <file|class name> -public <file|class name>" +
        LF +
        "        [-privatePassword <password>] [-classes -passwordClass <class name> -privatePasswordClass <class" +
        LF +
        "        name> [-privatePackage <package>] [-publicPackage <package>] [-passwordPackage <package>]" + LF +
        "        [-privatePasswordPackage <package>]]" + LF +
        " -classes                             Specify to generate compilable Java classes instead of key files" +
        LF +
        " -help                                Display this help message" + LF +
        " -interactive                         Specify to use interactive mode and ignore command-line options" +
        LF +
        " -password <password>                 The password to use to encrypt the public and private keys" + LF +
        "                                      (required unless in interactive mode)" + LF +
        " -passwordClass <class name>          The name of the password storage class to generate (optional," + LF +
        "                                      ignored unless generating classes)" + LF +
        " -passwordPackage <package>           The name of the package to use for the password storage class" + LF +
        "                                      (optional, ignored unless generating classes)" + LF +
        " -private <file|class name>           The name of the private key file or class to generate (required" +
        LF +
        "                                      unless in interactive mode)" + LF +
        " -privatePackage <package>            The name of the package to use for the private key class " +
        "(optional," +
        LF +
        "                                      ignored unless generating classes)" + LF +
        " -privatePassword <password>          A different password to use to encrypt the private key (optional)" +
        LF +
        " -privatePasswordClass <class name>   The name of the private key password storage class to generate" +
        LF +
        "                                      (optional, ignored unless generating classes)" + LF +
        " -privatePasswordPackage <package>    The name of the package to use for the private key password " +
        "storage" +
        LF +
        "                                      class (optional, ignored unless generating classes)" + LF +
        " -public <file|class name>            The name of the public key file or class to generate (required" +
        LF +
        "                                      unless in interactive mode)" + LF +
        " -publicPackage <package>             The name of the package to use for the public key class (optional," +
        LF +
        "                                      ignored unless generating classes)" + LF,
        output
    );
}
 
Example 20
Source File: NoteTest.java    From Explorer with Apache License 2.0 2 votes vote down vote up
@Test
public void testExportToFile() throws Exception {


    String basePath = "src" + File.separator + "test" + File.separator + "resources" + File.separator;

    File f = new File(basePath + "Test.json");
    if (f.exists()){
        f.delete();
    }

    ExplorerConfiguration conf = mock(ExplorerConfiguration.class);
    expect(conf.getString(ExplorerConfiguration.ConfVars.EXPLORER_ENCODING)).andReturn("UTF-8");
    replay(conf);
    NoteInterpreterLoader replLoader = mock(NoteInterpreterLoader.class);
    JobListenerFactory jobListenerFactory = mock(JobListenerFactory.class);

    Scheduler quartzShed =  mock(Scheduler.class);
    Note note = new Note(conf,replLoader,jobListenerFactory,quartzShed);
    note.setName("TEST_NOTE");
    Whitebox.setInternalState(note, "id", "2AZE9X5GG");
    Whitebox.setInternalState(note, "creationDate", "lun, 5 oct, 10:10 AM");

    JobListener jobListener = mock(JobListener.class);
    jobListener.beforeStatusChange(anyObject(Job.class), eq(com.stratio.explorer.scheduler.Job.Status.READY), eq(com.stratio.explorer.scheduler.Job.Status.FINISHED));
    EasyMock.expectLastCall();
    Paragraph paragraph = new Paragraph(jobListener, replLoader);
    paragraph.setTitle("PARAGRAPH_TITLE");
    Whitebox.setInternalState(paragraph, "dateCreated", new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").parse("05/01/1970 12:16:40"));
    Whitebox.setInternalState(paragraph, "jobName", "paragraph_1444033271219_-1226681848");


    List<Paragraph> paragraphList = new LinkedList<>();
    paragraphList.add(paragraph);

    note.addParagraphs(paragraphList);

    Whitebox.setInternalState(paragraph, "id", "20151005-095152_2104354711");

    replay(jobListener);
    note.exportToFile(basePath, "Test");


    assertTrue("The file must Exist", f.exists());
    File fileExpected = new File(basePath+"Test_Export_default.json");
    assertEquals("The file must be the correct content",FileUtils.readLines(fileExpected),FileUtils.readLines(f));


     f.delete(); //We clean the enviroment


}