コード例 #1
0
  @Before
  public void setUp() throws Exception {

    ShadowLog.stream = System.out;
    transcript = new Transcript();

    context = new Activity();

    ObsDetails obsDetails = ObsDetails.getInstance();
    obsDetails.setCompanyCode("coco");
    obsDetails.setUsername("david");

    final String[] fList = context.fileList();
    boolean configExists = false;
    f =
        new File(
            HttpMessageConverterTest.class.getClassLoader().getResource(TOKEN_FILE_NAME).toURI());
    Assert.assertTrue(f.exists());

    for (String fname : fList) {
      configExists = configExists || TOKEN_FILE_NAME.equals(fname);
    }
    try {

      f =
          new File(
              HttpMessageConverterTest.class.getClassLoader().getResource(TOKEN_FILE_NAME).toURI());
      Assert.assertTrue(f.exists());

      tokenConfiguration = (new TokenConfiguration()).load(f, "lucky13".toCharArray());
      if (tokenConfiguration.getDomains().size() == 0) {
        TokenConfiguration.save(tokenConfiguration, f, "lucky13".toCharArray());
        setupFacade.init();

      } else {
        Logger.debug("Unable to create token Configuration");
      }
    } catch (Exception e) {
      Logger.debug("HomeMenu" + "Exception thrown: " + e.getMessage());
    }

    Robolectric.getBackgroundScheduler().pause();
    Robolectric.getUiThreadScheduler().pause();
  }
コード例 #2
0
  @Test
  public void testAPIRequests() throws Exception {

    auth = new AuthenticationFacade();
    setupFacade = new SetupFacade();
    messageFacade = new SecureMessageFacade();

    TestOBSApplication.injectMocks(setupFacade);
    TestOBSApplication.injectMocks(auth);
    TestOBSApplication.injectMocks(messageFacade);
    TestOBSApplication.injectMocks(setupFacade.getRestClient());

    setupFacade.init(tokenConfiguration);

    setupFacade.login(
        "Asdf1234",
        new Callback() {
          @Override
          public void onTaskCompleted(Object result) {
            Log.d("HDB: onTaskCompleted", "Login Successful");
            messageFacade.getMessages(
                new Callback<GetSecureMessagesResponse>() {
                  @Override
                  public void onTaskCompleted(GetSecureMessagesResponse result) {
                    Log.d("HDB: SecureMessageFacadeTest.onTaskCompleted", result.toString());

                    for (SecureMessage msg :
                        result
                            .getMessages()
                            .subList(
                                0,
                                result.getMessages().size() < 10
                                    ? result.getMessages().size()
                                    : 10)) {
                      Log.d(
                          "HDB: Message",
                          "Fr: "
                              + msg.getOriginatingCompanyCode()
                              + "."
                              + msg.getOriginatingUsername()
                              + ", Subject: "
                              + msg.getSubject()
                              + ", Date: "
                              + msg.getDate());
                    }
                    Log.d("HDB: onTaskCompleted", result.toString());

                    Robolectric.runBackgroundTasks();
                    Robolectric.runUiThreadTasks();
                  }

                  @Override
                  public void onTaskFailure(String Reason) {}
                });

            Robolectric.runBackgroundTasks();
            Robolectric.runUiThreadTasks();
          }

          @Override
          public void onTaskFailure(String Reason) {
            Log.e("onTaskFailure", "Login Failed");
          }
        });
    Robolectric.runBackgroundTasks();
    Robolectric.runUiThreadTasks();
    Robolectric.runBackgroundTasks();
    Robolectric.runUiThreadTasks();
    Robolectric.runBackgroundTasks();
    Robolectric.runUiThreadTasks();
  }