Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #119 from vase4kin/dev
Browse files Browse the repository at this point in the history
Release 1.2.9
  • Loading branch information
vase4kin authored Apr 5, 2018
2 parents 073a4d1 + ac12c83 commit 5e90ef0
Show file tree
Hide file tree
Showing 47 changed files with 776 additions and 341 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[![License](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![Circle CI](https://circleci.com/gh/vase4kin/TeamCityApp/tree/master.svg?style=shield)](https://circleci.com/gh/vase4kin/TeamCityApp/tree/master)
[![codecov](https://codecov.io/gh/vase4kin/TeamCityApp/branch/master/graph/badge.svg)](https://codecov.io/gh/vase4kin/TeamCityApp)
[![Release](https://img.shields.io/badge/release-1.2.8-blue.svg)](https://github.com/vase4kin/TeamCityApp/releases/latest)
[![Release](https://img.shields.io/badge/release-1.2.9-blue.svg)](https://github.com/vase4kin/TeamCityApp/releases/latest)

```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.github.vase4kin.teamcityapp.dagger.modules.AppModule.CLIENT_AUTH;
import static com.github.vase4kin.teamcityapp.dagger.modules.AppModule.CLIENT_BASE;
import static com.github.vase4kin.teamcityapp.dagger.modules.AppModule.CLIENT_BASE_UNSAFE;
import static com.github.vase4kin.teamcityapp.dagger.modules.Mocks.URL;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -109,6 +110,10 @@ public void setComponent(AppComponent appComponent) {
@Mock
private OkHttpClient mClientBase;

@Named(CLIENT_BASE_UNSAFE)
@Mock
private OkHttpClient unsafeOkHttpClient;

@Named(CLIENT_AUTH)
@Mock
private OkHttpClient mClientAuth;
Expand All @@ -126,6 +131,7 @@ public void setUp() {
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getAppInjector().sharedUserStorage().clearAll();
when(mClientBase.newCall(Matchers.any(Request.class))).thenReturn(mCall);
when(unsafeOkHttpClient.newCall(Matchers.any(Request.class))).thenReturn(mCall);
mActivityRule.launchActivity(null);
}

Expand Down Expand Up @@ -165,6 +171,49 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
SharedUserStorage storageUtils = SharedUserStorage.init(mActivityRule.getActivity(), null);
assertThat(storageUtils.hasGuestAccountWithUrl(URL), is(true));
assertThat(storageUtils.getActiveUser().getTeamcityUrl(), is(URL));
assertThat(storageUtils.getActiveUser().isSslDisabled(), is(false));
}

/**
* Verifies that user can be logged in as guest user with correct account url ignoring ssl
*/
@Test
public void testUserCanCreateGuestUserAccountWithCorrectUrlIgnoringSsl() 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.disable_ssl_switch)).perform(click());
onView(withText(R.string.warning_ssl_dialog_content)).check(matches(isDisplayed()));
onView(withText(R.string.dialog_ok_title)).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));
assertThat(storageUtils.getActiveUser().isSslDisabled(), is(true));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static void disableOnboarding() {
public void setUp() {
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getRestApiInjector().sharedUserStorage().clearAll();
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL, false);
ConditionWatcher.setTimeoutLimit(TIMEOUT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static void disableOnboarding() {
public void setUp() {
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getRestApiInjector().sharedUserStorage().clearAll();
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL, false);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public static void disableOnboarding() {
public void setUp() {
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getRestApiInjector().sharedUserStorage().clearAll();
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL, false);
mActivityRule.launchActivity(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static void disableOnboarding() {
public void setUp() {
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getRestApiInjector().sharedUserStorage().clearAll();
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL, false);
when(mTeamCityService.listBuilds(anyString(), anyString())).thenReturn(Observable.just(new Builds(0, Collections.<Build>emptyList())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void setComponent(RestApiComponent restApiComponent) {
public void setUp() {
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getRestApiInjector().sharedUserStorage().clearAll();
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL, false);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static com.github.vase4kin.teamcityapp.dagger.modules.AppModule.CLIENT_AUTH;
import static com.github.vase4kin.teamcityapp.dagger.modules.AppModule.CLIENT_BASE;
import static com.github.vase4kin.teamcityapp.dagger.modules.AppModule.CLIENT_BASE_UNSAFE;
import static com.github.vase4kin.teamcityapp.dagger.modules.Mocks.URL;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.equalTo;
Expand Down Expand Up @@ -104,7 +105,11 @@ public void setComponent(AppComponent appComponent) {

@Named(CLIENT_BASE)
@Mock
private OkHttpClient mClientBase;
private OkHttpClient okHttpClient;

@Named(CLIENT_BASE_UNSAFE)
@Mock
private OkHttpClient unsafeOkHttpClient;

@Named(CLIENT_AUTH)
@Mock
Expand All @@ -120,7 +125,8 @@ public void setComponent(AppComponent appComponent) {
public void setUp() {
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getAppInjector().sharedUserStorage().clearAll();
when(mClientBase.newCall(Matchers.any(Request.class))).thenReturn(mCall);
when(okHttpClient.newCall(Matchers.any(Request.class))).thenReturn(mCall);
when(unsafeOkHttpClient.newCall(Matchers.any(Request.class))).thenReturn(mCall);
mActivityRule.launchActivity(null);
}

Expand Down Expand Up @@ -158,6 +164,47 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
SharedUserStorage storageUtils = app.getRestApiInjector().sharedUserStorage();
assertThat(storageUtils.hasGuestAccountWithUrl(savedUrl), is(true));
assertThat(storageUtils.getActiveUser().getTeamcityUrl(), is(savedUrl));
assertThat(storageUtils.getActiveUser().isSslDisabled(), is(false));
}

/**
* Verifies that user can be logged in as guest user with correct account url ignoring ssl
*/
@Test
public void testUserCanCreateGuestUserAccountWithCorrectUrlIgnoringSsl() {
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.disable_ssl_switch)).perform(click());
onView(withText(R.string.warning_ssl_dialog_content)).check(matches(isDisplayed()));
onView(withText(R.string.dialog_ok_title)).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));
assertThat(storageUtils.getActiveUser().isSslDisabled(), is(true));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static void disableOnboarding() {
public void setUp() {
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getAppInjector().sharedUserStorage().clearAll();
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL, false);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void setComponent(RestApiComponent restApiComponent) {
public void setUp() {
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getRestApiInjector().sharedUserStorage().clearAll();
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
app.getRestApiInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL, false);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void setUp() {
public void testUserNavigatesToRootProjectsActivityIgnored() throws Exception {
// Prepate data
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getAppInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
app.getAppInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL, false);

// Launch activity
mActivityRule.launchActivity(null);
Expand Down Expand Up @@ -112,7 +112,7 @@ public void testUserNavigatesToLoginActivityIgnored() throws Exception {
public void testUserNavigatesToRootProjectsActivity() throws Exception {
// Prepate data
TeamCityApplication app = (TeamCityApplication) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
app.getAppInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL);
app.getAppInjector().sharedUserStorage().saveGuestUserAccountAndSetItAsActive(Mocks.URL, false);

// Launch activity
mActivityRule.launchActivity(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import okhttp3.OkHttpClient;

import static com.github.vase4kin.teamcityapp.dagger.modules.AppModule.CLIENT_BASE;
import static com.github.vase4kin.teamcityapp.dagger.modules.AppModule.CLIENT_BASE_UNSAFE;

@Module
public class CreateAccountModule {
Expand All @@ -63,9 +64,10 @@ CreateAccountView providesCreateAccountView() {
@Provides
CreateAccountDataManager providesCreateAccountDataManager(Context context,
@Named(CLIENT_BASE) OkHttpClient okHttpClient,
@Named(CLIENT_BASE_UNSAFE) OkHttpClient unsafeOkHttpClient,
SharedUserStorage sharedUserStorage,
UrlFormatter urlFormatter) {
return new CreateAccountDataManagerImpl(context, okHttpClient, sharedUserStorage, urlFormatter);
return new CreateAccountDataManagerImpl(context, okHttpClient, unsafeOkHttpClient, sharedUserStorage, urlFormatter);
}

@Provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,47 @@ public interface CreateAccountDataManager {
* @param url - TeamCity server url
* @param userName - Username
* @param password - Password
* @param isSslDisabled - ssl state
*/
void authUser(@NonNull CustomOnLoadingListener<String> listener, String url, String userName, String password);
void authUser(@NonNull CustomOnLoadingListener<String> listener,
String url,
String userName,
String password,
boolean isSslDisabled);

/**
* Server guest auth
*
* @param listener - to receive callbacks on {@link com.github.vase4kin.teamcityapp.account.create.presenter.CreateAccountPresenterImpl}
* @param url - TeamCity server url
* @param isSslDisabled - ssl state
*/
void authGuestUser(@NonNull CustomOnLoadingListener<String> listener, String url);
void authGuestUser(@NonNull CustomOnLoadingListener<String> listener,
String url,
boolean isSslDisabled);

/**
* Save user account in the local storage
*
* @param url - TeamCity server url
* @param userName - User name
* @param password - Password
* @param isSslDisabled - ssl state
* @param listener to receive data save callbacks§
*/
void saveNewUserAccount(String serverUrl, String userName, String password, OnLoadingListener<String> listener);
void saveNewUserAccount(String serverUrl,
String userName,
String password,
boolean isSslDisabled,
OnLoadingListener<String> listener);

/**
* Save guest user account in the local storage
*
* @param url - TeamCity server url
* @param isSslDisabled - ssl state
*/
void saveGuestUserAccount(String url);
void saveGuestUserAccount(String url, boolean isSslDisabled);

/**
* Init {@link com.github.vase4kin.teamcityapp.dagger.components.RestApiComponent}
Expand Down
Loading

0 comments on commit 5e90ef0

Please sign in to comment.