@Test
  public void testConfigureAccumuloInputFormatWithIterators() throws Exception {
    AccumuloConnectionParameters accumuloParams = new AccumuloConnectionParameters(conf);
    ColumnMapper columnMapper =
        new ColumnMapper(
            conf.get(AccumuloSerDeParameters.COLUMN_MAPPINGS),
            conf.get(AccumuloSerDeParameters.DEFAULT_STORAGE_TYPE),
            columnNames,
            columnTypes);
    Set<Pair<Text, Text>> cfCqPairs =
        inputformat.getPairCollection(columnMapper.getColumnMappings());
    List<IteratorSetting> iterators = new ArrayList<IteratorSetting>();
    Set<Range> ranges = Collections.singleton(new Range());
    String instanceName = "realInstance";
    String zookeepers = "host1:2181,host2:2181,host3:2181";

    IteratorSetting cfg = new IteratorSetting(50, PrimitiveComparisonFilter.class);
    cfg.addOption(PrimitiveComparisonFilter.P_COMPARE_CLASS, StringCompare.class.getName());
    cfg.addOption(PrimitiveComparisonFilter.COMPARE_OPT_CLASS, Equal.class.getName());
    cfg.addOption(PrimitiveComparisonFilter.CONST_VAL, "dave");
    cfg.addOption(PrimitiveComparisonFilter.COLUMN, "person:name");
    iterators.add(cfg);

    cfg = new IteratorSetting(50, PrimitiveComparisonFilter.class);
    cfg.addOption(PrimitiveComparisonFilter.P_COMPARE_CLASS, IntCompare.class.getName());
    cfg.addOption(PrimitiveComparisonFilter.COMPARE_OPT_CLASS, Equal.class.getName());
    cfg.addOption(PrimitiveComparisonFilter.CONST_VAL, "50");
    cfg.addOption(PrimitiveComparisonFilter.COLUMN, "person:age");
    iterators.add(cfg);

    ZooKeeperInstance zkInstance = Mockito.mock(ZooKeeperInstance.class);
    HiveAccumuloTableInputFormat mockInputFormat = Mockito.mock(HiveAccumuloTableInputFormat.class);

    // Stub out the ZKI mock
    Mockito.when(zkInstance.getInstanceName()).thenReturn(instanceName);
    Mockito.when(zkInstance.getZooKeepers()).thenReturn(zookeepers);

    // Call out to the real configure method
    Mockito.doCallRealMethod()
        .when(mockInputFormat)
        .configure(conf, zkInstance, con, accumuloParams, columnMapper, iterators, ranges);

    // Also compute the correct cf:cq pairs so we can assert the right argument was passed
    Mockito.doCallRealMethod()
        .when(mockInputFormat)
        .getPairCollection(columnMapper.getColumnMappings());

    mockInputFormat.configure(
        conf, zkInstance, con, accumuloParams, columnMapper, iterators, ranges);

    // Verify that the correct methods are invoked on AccumuloInputFormat
    Mockito.verify(mockInputFormat).setZooKeeperInstance(conf, instanceName, zookeepers, false);
    Mockito.verify(mockInputFormat).setConnectorInfo(conf, USER, new PasswordToken(PASS));
    Mockito.verify(mockInputFormat).setInputTableName(conf, TEST_TABLE);
    Mockito.verify(mockInputFormat)
        .setScanAuthorizations(conf, con.securityOperations().getUserAuthorizations(USER));
    Mockito.verify(mockInputFormat).addIterators(conf, iterators);
    Mockito.verify(mockInputFormat).setRanges(conf, ranges);
    Mockito.verify(mockInputFormat).fetchColumns(conf, cfCqPairs);
  }
  @Before
  public void initComponents() {
    view = new MvpView() {};

    presenter = Mockito.mock(MvpPresenter.class);
    callback = Mockito.mock(PartialMvpDelegateCallbackImpl.class);
    Mockito.doCallRealMethod().when(callback).setPresenter(presenter);
    Mockito.doCallRealMethod().when(callback).getPresenter();

    Mockito.when(callback.getMvpView()).thenReturn(view);

    delegate = new ViewGroupMvpDelegateImpl<>(callback);
  }
  public static PrintJob createTestPrintJob(PrintFileProcessor processor)
      throws InappropriateDeviceException, Exception {
    PrintJob printJob = Mockito.mock(PrintJob.class);
    Printer printer = Mockito.mock(Printer.class);
    PrinterConfiguration printerConfiguration = Mockito.mock(PrinterConfiguration.class);
    SlicingProfile slicingProfile = Mockito.mock(SlicingProfile.class);
    InkConfig inkConfiguration = Mockito.mock(InkConfig.class);
    eGENERICGCodeControl gCode = Mockito.mock(eGENERICGCodeControl.class);
    SerialCommunicationsPort serialPort = Mockito.mock(SerialCommunicationsPort.class);
    MonitorDriverConfig monitorConfig = Mockito.mock(MonitorDriverConfig.class);
    MachineConfig machine = Mockito.mock(MachineConfig.class);

    Mockito.when(printJob.getJobFile()).thenReturn(new File("jobname.txt"));
    Mockito.when(printJob.getPrinter()).thenReturn(printer);
    Mockito.when(printer.getPrinterFirmwareSerialPort()).thenReturn(serialPort);
    Mockito.when(printJob.getPrintFileProcessor()).thenReturn(processor);
    Mockito.when(printer.getConfiguration()).thenReturn(printerConfiguration);
    Mockito.when(printer.waitForPauseIfRequired()).thenReturn(true);
    Mockito.when(printer.isPrintActive()).thenReturn(true);
    Mockito.when(printerConfiguration.getSlicingProfile()).thenReturn(slicingProfile);
    Mockito.when(slicingProfile.getSelectedInkConfig()).thenReturn(inkConfiguration);
    Mockito.when(slicingProfile.getDirection()).thenReturn(BuildDirection.Bottom_Up);
    Mockito.when(printer.getGCodeControl()).thenReturn(gCode);
    Mockito.when(slicingProfile.getgCodeLift()).thenReturn("Lift z");
    Mockito.doCallRealMethod()
        .when(gCode)
        .executeGCodeWithTemplating(Mockito.any(PrintJob.class), Mockito.anyString());
    Mockito.when(printer.getConfiguration().getMachineConfig()).thenReturn(machine);
    Mockito.when(printer.getConfiguration().getMachineConfig().getMonitorDriverConfig())
        .thenReturn(monitorConfig);
    return printJob;
  }
  @Test
  public void testConfigureAccumuloInputFormatWithAuthorizations() throws Exception {
    AccumuloConnectionParameters accumuloParams = new AccumuloConnectionParameters(conf);
    conf.set(AccumuloSerDeParameters.AUTHORIZATIONS_KEY, "foo,bar");
    ColumnMapper columnMapper =
        new ColumnMapper(
            conf.get(AccumuloSerDeParameters.COLUMN_MAPPINGS),
            conf.get(AccumuloSerDeParameters.DEFAULT_STORAGE_TYPE),
            columnNames,
            columnTypes);
    Set<Pair<Text, Text>> cfCqPairs =
        inputformat.getPairCollection(columnMapper.getColumnMappings());
    List<IteratorSetting> iterators = Collections.emptyList();
    Set<Range> ranges = Collections.singleton(new Range());
    String instanceName = "realInstance";
    String zookeepers = "host1:2181,host2:2181,host3:2181";

    ZooKeeperInstance zkInstance = Mockito.mock(ZooKeeperInstance.class);
    HiveAccumuloTableInputFormat mockInputFormat = Mockito.mock(HiveAccumuloTableInputFormat.class);

    // Stub out the ZKI mock
    Mockito.when(zkInstance.getInstanceName()).thenReturn(instanceName);
    Mockito.when(zkInstance.getZooKeepers()).thenReturn(zookeepers);

    // Call out to the real configure method
    Mockito.doCallRealMethod()
        .when(mockInputFormat)
        .configure(conf, zkInstance, con, accumuloParams, columnMapper, iterators, ranges);

    // Also compute the correct cf:cq pairs so we can assert the right argument was passed
    Mockito.doCallRealMethod()
        .when(mockInputFormat)
        .getPairCollection(columnMapper.getColumnMappings());

    mockInputFormat.configure(
        conf, zkInstance, con, accumuloParams, columnMapper, iterators, ranges);

    // Verify that the correct methods are invoked on AccumuloInputFormat
    Mockito.verify(mockInputFormat).setZooKeeperInstance(conf, instanceName, zookeepers, false);
    Mockito.verify(mockInputFormat).setConnectorInfo(conf, USER, new PasswordToken(PASS));
    Mockito.verify(mockInputFormat).setInputTableName(conf, TEST_TABLE);
    Mockito.verify(mockInputFormat).setScanAuthorizations(conf, new Authorizations("foo,bar"));
    Mockito.verify(mockInputFormat).addIterators(conf, iterators);
    Mockito.verify(mockInputFormat).setRanges(conf, ranges);
    Mockito.verify(mockInputFormat).fetchColumns(conf, cfCqPairs);
  }
  @Test
  public void testCreateTicket() throws Exception {

    Ticket ticket = new Ticket();
    ticket.setTicketId(1);
    Mockito.when(ticketDao.createTicket(ticket)).thenReturn(ticket);
    Mockito.doCallRealMethod().when(emailSenderService).newTicketCreated(ticket.getEmail());

    MessageResponse messageResponse = ticketService.createTicket(ticket);
    assertTrue(messageResponse.getCode() == 1);
  }
  @Test
  public void testConfigureMockAccumuloInputFormat() throws Exception {
    AccumuloConnectionParameters accumuloParams = new AccumuloConnectionParameters(conf);
    ColumnMapper columnMapper =
        new ColumnMapper(
            conf.get(AccumuloSerDeParameters.COLUMN_MAPPINGS),
            conf.get(AccumuloSerDeParameters.DEFAULT_STORAGE_TYPE),
            columnNames,
            columnTypes);
    Set<Pair<Text, Text>> cfCqPairs =
        inputformat.getPairCollection(columnMapper.getColumnMappings());
    List<IteratorSetting> iterators = Collections.emptyList();
    Set<Range> ranges = Collections.singleton(new Range());

    HiveAccumuloTableInputFormat mockInputFormat = Mockito.mock(HiveAccumuloTableInputFormat.class);

    // Call out to the real configure method
    Mockito.doCallRealMethod()
        .when(mockInputFormat)
        .configure(conf, mockInstance, con, accumuloParams, columnMapper, iterators, ranges);

    // Also compute the correct cf:cq pairs so we can assert the right argument was passed
    Mockito.doCallRealMethod()
        .when(mockInputFormat)
        .getPairCollection(columnMapper.getColumnMappings());

    mockInputFormat.configure(
        conf, mockInstance, con, accumuloParams, columnMapper, iterators, ranges);

    // Verify that the correct methods are invoked on AccumuloInputFormat
    Mockito.verify(mockInputFormat).setMockInstance(conf, mockInstance.getInstanceName());
    Mockito.verify(mockInputFormat).setConnectorInfo(conf, USER, new PasswordToken(PASS));
    Mockito.verify(mockInputFormat).setInputTableName(conf, TEST_TABLE);
    Mockito.verify(mockInputFormat)
        .setScanAuthorizations(conf, con.securityOperations().getUserAuthorizations(USER));
    Mockito.verify(mockInputFormat).addIterators(conf, iterators);
    Mockito.verify(mockInputFormat).setRanges(conf, ranges);
    Mockito.verify(mockInputFormat).fetchColumns(conf, cfCqPairs);
  }
Exemplo n.º 7
0
 private void mockSession() {
   final EventLoop eventLoop = Mockito.mock(EventLoop.class);
   final Channel channel = Mockito.mock(Channel.class);
   final ChannelPipeline pipeline = Mockito.mock(ChannelPipeline.class);
   Mockito.doReturn(null)
       .when(eventLoop)
       .schedule(any(Runnable.class), any(long.class), any(TimeUnit.class));
   Mockito.doReturn(eventLoop).when(channel).eventLoop();
   Mockito.doReturn(Boolean.TRUE).when(channel).isWritable();
   Mockito.doReturn(null).when(channel).close();
   Mockito.doReturn(pipeline).when(channel).pipeline();
   Mockito.doCallRealMethod().when(channel).toString();
   Mockito.doReturn(pipeline).when(pipeline).addLast(Mockito.any(ChannelHandler.class));
   Mockito.doReturn(new DefaultChannelPromise(channel))
       .when(channel)
       .writeAndFlush(any(Notification.class));
   Mockito.doReturn(new InetSocketAddress("localhost", 12345)).when(channel).remoteAddress();
   Mockito.doReturn(new InetSocketAddress("localhost", 12345)).when(channel).localAddress();
   final List<BgpParameters> params =
       Lists.newArrayList(
           new BgpParametersBuilder()
               .setOptionalCapabilities(
                   Lists.newArrayList(
                       new OptionalCapabilitiesBuilder()
                           .setCParameters(
                               new CParametersBuilder()
                                   .addAugmentation(
                                       CParameters1.class,
                                       new CParameters1Builder()
                                           .setMultiprotocolCapability(
                                               new MultiprotocolCapabilityBuilder()
                                                   .setAfi(Ipv4AddressFamily.class)
                                                   .setSafi(UnicastSubsequentAddressFamily.class)
                                                   .build())
                                           .build())
                                   .build())
                           .build()))
               .build());
   this.session =
       new BGPSessionImpl(
           this.classic,
           channel,
           new OpenBuilder()
               .setBgpIdentifier(new Ipv4Address("1.1.1.1"))
               .setHoldTimer(50)
               .setMyAsNumber(72)
               .setBgpParameters(params)
               .build(),
           30,
           null);
 }
  @Test
  public void testUpdateRetryWithError() {
    Repository<Entity> mockRepo = Mockito.spy(repository);
    Map<String, Object> studentBody = buildTestStudentEntity();
    Map<String, Object> studentMetaData = new HashMap<String, Object>();
    Entity entity = new MongoEntity("student", null, studentBody, studentMetaData);
    int noOfRetries = 3;

    Mockito.doThrow(new InvalidDataAccessApiUsageException("Test Exception"))
        .when(mockRepo)
        .update("student", entity, false);
    Mockito.doCallRealMethod().when(mockRepo).updateWithRetries("student", entity, noOfRetries);

    try {
      mockRepo.updateWithRetries("student", entity, noOfRetries);
    } catch (InvalidDataAccessApiUsageException ex) {
      assertEquals(ex.getMessage(), "Test Exception");
    }

    Mockito.verify(mockRepo, Mockito.times(noOfRetries)).update("student", entity, false);
  }
  @Test
  @Ignore("Need to work out how to check set subscription values")
  public void testPassingInvalidSubscriptionTypeSetsSubscriptionToNone() throws Exception {

    IQ request =
        toIq(
            readStanzaAsString("/iq/pubsub/subscribe/authorizationPendingGrantReply.stanza")
                .replaceFirst(
                    "subscription='subscribed'", "subscription='i-can-haz-all-the-items'"));

    NodeAffiliation subscriptionMockActor = Mockito.mock(NodeAffiliation.class);
    Mockito.when(subscriptionMockActor.getAffiliation()).thenReturn(Affiliations.owner);

    NodeSubscription subscriptionMockSubscriber = Mockito.mock(NodeSubscription.class);
    Mockito.when(subscriptionMockSubscriber.getSubscription()).thenReturn(Subscriptions.subscribed);

    Mockito.when(dataStore.nodeExists(node)).thenReturn(true);
    Mockito.when(dataStore.getUserAffiliation(node, jid)).thenReturn(subscriptionMockActor);
    Mockito.doCallRealMethod()
        .when(dataStore)
        .addUserSubscription(Mockito.any(NodeSubscription.class));
    Mockito.when(dataStore.getUserSubscription(node, new JID(subscriber)))
        .thenReturn(subscriptionMockSubscriber);

    event.setChannelManager(dataStore);
    event.process(element, jid, request, null);

    NodeSubscription subscriptionMock =
        new NodeSubscriptionImpl(
            node,
            new JID("*****@*****.**"),
            new JID("*****@*****.**"),
            Subscriptions.none);

    /*
     * subscriptionMock Mockito.anyString(), Mockito.any(JID.class),
     * Mockito.any(JID.class), Mockito.eq(Subscriptions.none));
     */
    Mockito.verify(dataStore).addUserSubscription(subscriptionMock);
  }
  @Test
  public void testCreateRetryWithError() {
    Repository<Entity> mockRepo = Mockito.spy(repository);
    Map<String, Object> studentBody = buildTestStudentEntity();
    Map<String, Object> studentMetaData = new HashMap<String, Object>();
    int noOfRetries = 5;

    Mockito.doThrow(new MongoException("Test Exception"))
        .when(((MongoEntityRepository) mockRepo))
        .internalCreate("student", null, studentBody, studentMetaData, "student");
    Mockito.doCallRealMethod()
        .when(mockRepo)
        .createWithRetries("student", null, studentBody, studentMetaData, "student", noOfRetries);

    try {
      mockRepo.createWithRetries(
          "student", null, studentBody, studentMetaData, "student", noOfRetries);
    } catch (MongoException ex) {
      assertEquals(ex.getMessage(), "Test Exception");
    }

    Mockito.verify((MongoEntityRepository) mockRepo, Mockito.times(noOfRetries))
        .internalCreate("student", null, studentBody, studentMetaData, "student");
  }