Search in sources :

Example 1 with Agents

use of com.github.vase4kin.teamcityapp.agents.api.Agents in project TeamCityApp by vase4kin.

the class AgentsDataManagerImpl method loadCount.

/**
 * {@inheritDoc}
 */
@Override
public void loadCount(@NonNull final OnLoadingListener<Integer> loadingListener) {
    mSubscriptions.clear();
    Subscription subscription = mRepository.listAgents(null, "count", null, false).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Agents>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            loadingListener.onSuccess(0);
        }

        @Override
        public void onNext(Agents response) {
            loadingListener.onSuccess(response.getCount());
        }
    });
    mSubscriptions.add(subscription);
}
Also used : Agents(com.github.vase4kin.teamcityapp.agents.api.Agents) Subscription(rx.Subscription)

Example 2 with Agents

use of com.github.vase4kin.teamcityapp.agents.api.Agents in project TeamCityApp by vase4kin.

the class RunBuildInteractorImpl method loadAgents.

/**
 * {@inheritDoc}
 */
@Override
public void loadAgents(final OnLoadingListener<List<Agent>> loadingListener) {
    Subscription queueBuildSubscription = mRepository.buildType(mBuildTypeId, false).flatMap(new Func1<BuildType, Observable<Agents>>() {

        @Override
        public Observable<Agents> call(BuildType buildType) {
            boolean isCompatibleAgentsSupported = buildType.getCompatibleAgents() != null;
            if (isCompatibleAgentsSupported) {
                // TODO: No hardcode
                String locator = String.format("compatible:(buildType:(id:%s))", mBuildTypeId);
                return mRepository.listAgents(null, null, locator, false);
            } else {
                return mRepository.listAgents(false, null, null, false);
            }
        }
    }).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Observer<Agents>() {

        @Override
        public void onCompleted() {
        }

        @Override
        public void onError(Throwable e) {
            loadingListener.onFail(e.getMessage());
        }

        @Override
        public void onNext(Agents agents) {
            loadingListener.onSuccess(agents.getObjects());
        }
    });
    mSubscription.add(queueBuildSubscription);
}
Also used : Agents(com.github.vase4kin.teamcityapp.agents.api.Agents) BuildType(com.github.vase4kin.teamcityapp.navigation.api.BuildType) CompositeSubscription(rx.subscriptions.CompositeSubscription) Subscription(rx.Subscription) Func1(rx.functions.Func1)

Example 3 with Agents

use of com.github.vase4kin.teamcityapp.agents.api.Agents in project TeamCityApp by vase4kin.

the class RunBuildActivityTest method testUserCanSeeChooseAgentIfAgentsAvailable.

@Test
public void testUserCanSeeChooseAgentIfAgentsAvailable() throws Exception {
    // Prepare mocks
    List<Agent> agents = new ArrayList<>();
    Agent agent = new Agent("agent 1");
    agents.add(agent);
    when(mTeamCityService.listAgents(false, null, null)).thenReturn(Observable.just(new Agents(1, agents)));
    // Prepare intent
    Intent intent = new Intent();
    intent.putExtra(RunBuildInteractor.EXTRA_BUILD_TYPE_ID, "href");
    // Starting the activity
    mActivityRule.launchActivity(intent);
    // Choose agent
    onView(withId(R.id.chooser_agent)).perform(click());
    onView(withText("agent 1")).perform(click());
    // Starting the build
    onView(withId(R.id.fab_queue_build)).perform(click());
    // Checking that build was triggered with agent
    verify(mTeamCityService).queueBuild(mBuildCaptor.capture());
    Build capturedBuild = mBuildCaptor.getValue();
    assertThat(capturedBuild.getAgent(), is(agent));
    // Checking activity is finishing
    assertThat(mActivityRule.getActivity().isFinishing(), is(true));
}
Also used : Agent(com.github.vase4kin.teamcityapp.agents.api.Agent) Build(com.github.vase4kin.teamcityapp.buildlist.api.Build) ArrayList(java.util.ArrayList) Agents(com.github.vase4kin.teamcityapp.agents.api.Agents) Intent(android.content.Intent) Test(org.junit.Test)

Example 4 with Agents

use of com.github.vase4kin.teamcityapp.agents.api.Agents in project TeamCityApp by vase4kin.

the class Mocks method connectedAgents.

/**
 * MOCK
 *
 * @return connected agents
 */
public static Agents connectedAgents() {
    List<Agent> agents = new ArrayList<>();
    agents.add(new Agent("agent 1"));
    agents.add(new Agent("agent 2"));
    agents.add(new Agent("agent 3"));
    return new Agents(3, agents);
}
Also used : Agent(com.github.vase4kin.teamcityapp.agents.api.Agent) ArrayList(java.util.ArrayList) Agents(com.github.vase4kin.teamcityapp.agents.api.Agents)

Example 5 with Agents

use of com.github.vase4kin.teamcityapp.agents.api.Agents in project TeamCityApp by vase4kin.

the class Mocks method disconnectedAgents.

/**
 * MOCK
 *
 * @return disconnected agents
 */
public static Agents disconnectedAgents() {
    List<Agent> agents = new ArrayList<>();
    agents.add(new Agent("Mac mini 3434"));
    return new Agents(1, agents);
}
Also used : Agent(com.github.vase4kin.teamcityapp.agents.api.Agent) ArrayList(java.util.ArrayList) Agents(com.github.vase4kin.teamcityapp.agents.api.Agents)

Aggregations

Agents (com.github.vase4kin.teamcityapp.agents.api.Agents)5 Agent (com.github.vase4kin.teamcityapp.agents.api.Agent)3 ArrayList (java.util.ArrayList)3 Subscription (rx.Subscription)2 Intent (android.content.Intent)1 Build (com.github.vase4kin.teamcityapp.buildlist.api.Build)1 BuildType (com.github.vase4kin.teamcityapp.navigation.api.BuildType)1 Test (org.junit.Test)1 Func1 (rx.functions.Func1)1 CompositeSubscription (rx.subscriptions.CompositeSubscription)1