Search in sources :

Example 1 with SharedUserStorage

use of com.github.vase4kin.teamcityapp.storage.SharedUserStorage in project TeamCityApp by vase4kin.

the class LoginActivityTest method testUserCanCreateUserAccountWithCorrectUrlAndCredentials.

/**
 * Verifies that user can be logged in with correct account url and credentials
 */
@Ignore
@Test
public void testUserCanCreateUserAccountWithCorrectUrlAndCredentials() throws Throwable {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mCallbackArgumentCaptor.getValue().onResponse(mCall, new Response.Builder().request(new Request.Builder().url(URL).build()).protocol(Protocol.HTTP_1_0).code(200).build());
            return null;
        }
    }).when(mCall).enqueue(mCallbackArgumentCaptor.capture());
    onView(withId(R.id.teamcity_url)).perform(typeText(INPUT_URL), closeSoftKeyboard());
    onView(withId(R.id.user_name)).perform(typeText("user"), pressImeActionButton());
    onView(withId(R.id.password)).perform(typeText("pass"), pressImeActionButton());
    intended(allOf(hasComponent(RootProjectsActivity.class.getName()), hasExtras(hasEntry(equalTo(BundleExtractorValues.IS_NEW_ACCOUNT_CREATED), equalTo(true)))));
    TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
    SharedUserStorage storageUtils = app.getRestApiInjector().sharedUserStorage();
    assertThat(storageUtils.hasAccountWithUrl(URL, "user"), is(true));
    assertThat(storageUtils.getActiveUser().getTeamcityUrl(), is(URL));
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) RootProjectsActivity(com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity) SharedUserStorage(com.github.vase4kin.teamcityapp.storage.SharedUserStorage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TeamCityApplication(com.github.vase4kin.teamcityapp.TeamCityApplication) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with SharedUserStorage

use of com.github.vase4kin.teamcityapp.storage.SharedUserStorage in project TeamCityApp by vase4kin.

the class LoginActivityTest method testUserCanCreateAccountWithCorrectUrlWhichContainsPathByImeButton.

/**
 * Verifies that user can be logged in as guest with correct account url
 */
@Test
public void testUserCanCreateAccountWithCorrectUrlWhichContainsPathByImeButton() throws Throwable {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mCallbackArgumentCaptor.getValue().onResponse(mCall, new Response.Builder().request(new Request.Builder().url(URL).build()).protocol(Protocol.HTTP_1_0).message(MESSAGE_EMPTY).code(200).build());
            return null;
        }
    }).when(mCall).enqueue(mCallbackArgumentCaptor.capture());
    onView(withId(R.id.guest_user_switch)).perform(click());
    onView(withId(R.id.teamcity_url)).perform(typeText(INPUT_URL), pressImeActionButton());
    intended(allOf(hasComponent(RootProjectsActivity.class.getName()), hasExtras(hasEntry(equalTo(BundleExtractorValues.IS_NEW_ACCOUNT_CREATED), equalTo(true)))));
    TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
    SharedUserStorage storageUtils = app.getRestApiInjector().sharedUserStorage();
    assertThat(storageUtils.hasGuestAccountWithUrl(URL), is(true));
    assertThat(storageUtils.getActiveUser().getTeamcityUrl(), is(URL));
}
Also used : Response(okhttp3.Response) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) RootProjectsActivity(com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity) SharedUserStorage(com.github.vase4kin.teamcityapp.storage.SharedUserStorage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Request(okhttp3.Request) TeamCityApplication(com.github.vase4kin.teamcityapp.TeamCityApplication) Test(org.junit.Test)

Example 3 with SharedUserStorage

use of com.github.vase4kin.teamcityapp.storage.SharedUserStorage in project TeamCityApp by vase4kin.

the class CreateAccountActivityTest method testUserCanCreateGuestUserAccountWithCorrectUrl.

/**
 * Verifies that user can be logged in as guest user with correct account url
 */
@Test
public void testUserCanCreateGuestUserAccountWithCorrectUrl() throws Throwable {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mCallbackArgumentCaptor.getValue().onResponse(mCall, new Response.Builder().request(new Request.Builder().url(URL).build()).protocol(Protocol.HTTP_1_0).code(200).message("").build());
            return null;
        }
    }).when(mCall).enqueue(mCallbackArgumentCaptor.capture());
    onView(withId(R.id.teamcity_url)).perform(typeText(INPUT_URL), closeSoftKeyboard());
    onView(withId(R.id.guest_user_switch)).perform(click());
    onView(withId(R.id.action_create)).perform(click());
    intended(allOf(hasComponent(RootProjectsActivity.class.getName()), hasFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP), hasExtras(allOf(hasEntry(equalTo(BundleExtractorValues.IS_NEW_ACCOUNT_CREATED), equalTo(true)), hasEntry(equalTo(BundleExtractorValues.IS_REQUIRED_TO_RELOAD), equalTo(true)))), toPackage("com.github.vase4kin.teamcityapp.mock.debug")));
    SharedUserStorage storageUtils = SharedUserStorage.init(mActivityRule.getActivity(), null);
    assertThat(storageUtils.hasGuestAccountWithUrl(URL), is(true));
    assertThat(storageUtils.getActiveUser().getTeamcityUrl(), is(URL));
}
Also used : Response(okhttp3.Response) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) RootProjectsActivity(com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity) SharedUserStorage(com.github.vase4kin.teamcityapp.storage.SharedUserStorage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Request(okhttp3.Request) Test(org.junit.Test)

Example 4 with SharedUserStorage

use of com.github.vase4kin.teamcityapp.storage.SharedUserStorage in project TeamCityApp by vase4kin.

the class LoginActivityTest method testUserCanCreateAccountWithCorrectUrlByImeButton.

/**
 * Verifies that user can be logged in as guest with correct account url
 */
@Test
public void testUserCanCreateAccountWithCorrectUrlByImeButton() throws Throwable {
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mCallbackArgumentCaptor.getValue().onResponse(mCall, new Response.Builder().request(new Request.Builder().url(URL).build()).protocol(Protocol.HTTP_1_0).message(MESSAGE_EMPTY).code(200).build());
            return null;
        }
    }).when(mCall).enqueue(mCallbackArgumentCaptor.capture());
    onView(withId(R.id.guest_user_switch)).perform(click());
    onView(withId(R.id.teamcity_url)).perform(typeText(INPUT_URL), pressImeActionButton());
    intended(allOf(hasComponent(RootProjectsActivity.class.getName()), hasExtras(hasEntry(equalTo(BundleExtractorValues.IS_NEW_ACCOUNT_CREATED), equalTo(true)))));
    TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
    SharedUserStorage storageUtils = app.getRestApiInjector().sharedUserStorage();
    assertThat(storageUtils.hasGuestAccountWithUrl(URL), is(true));
    assertThat(storageUtils.getActiveUser().getTeamcityUrl(), is(URL));
}
Also used : Response(okhttp3.Response) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) RootProjectsActivity(com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity) SharedUserStorage(com.github.vase4kin.teamcityapp.storage.SharedUserStorage) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Request(okhttp3.Request) TeamCityApplication(com.github.vase4kin.teamcityapp.TeamCityApplication) Test(org.junit.Test)

Example 5 with SharedUserStorage

use of com.github.vase4kin.teamcityapp.storage.SharedUserStorage in project TeamCityApp by vase4kin.

the class LoginActivityTest method testUserCanCreateGuestUserAccountWithCorrectUrl.

/**
 * Verifies that user can be logged in as guest user with correct account url
 */
@Test
public void testUserCanCreateGuestUserAccountWithCorrectUrl() throws Throwable {
    final String urlWithPath = "https://teamcity.com/server";
    String savedUrl = urlWithPath.concat("/");
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            mCallbackArgumentCaptor.getValue().onResponse(mCall, new Response.Builder().request(new Request.Builder().url(urlWithPath).build()).protocol(Protocol.HTTP_1_0).message(MESSAGE_EMPTY).code(200).build());
            return null;
        }
    }).when(mCall).enqueue(mCallbackArgumentCaptor.capture());
    onView(withId(R.id.teamcity_url)).perform(typeText(urlWithPath.replace("https://", "")), closeSoftKeyboard());
    onView(withId(R.id.guest_user_switch)).perform(click());
    onView(withId(R.id.btn_login)).perform(click());
    intended(allOf(hasComponent(RootProjectsActivity.class.getName()), hasExtras(hasEntry(equalTo(BundleExtractorValues.IS_NEW_ACCOUNT_CREATED), equalTo(true)))));
    TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
    SharedUserStorage storageUtils = app.getRestApiInjector().sharedUserStorage();
    assertThat(storageUtils.hasGuestAccountWithUrl(savedUrl), is(true));
    assertThat(storageUtils.getActiveUser().getTeamcityUrl(), is(savedUrl));
}
Also used : SharedUserStorage(com.github.vase4kin.teamcityapp.storage.SharedUserStorage) Request(okhttp3.Request) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Response(okhttp3.Response) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) RootProjectsActivity(com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TeamCityApplication(com.github.vase4kin.teamcityapp.TeamCityApplication) Test(org.junit.Test)

Aggregations

RootProjectsActivity (com.github.vase4kin.teamcityapp.root.view.RootProjectsActivity)6 SharedUserStorage (com.github.vase4kin.teamcityapp.storage.SharedUserStorage)6 Test (org.junit.Test)6 Mockito.doAnswer (org.mockito.Mockito.doAnswer)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 Answer (org.mockito.stubbing.Answer)6 TeamCityApplication (com.github.vase4kin.teamcityapp.TeamCityApplication)5 Request (okhttp3.Request)4 Response (okhttp3.Response)4 Ignore (org.junit.Ignore)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1