Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make BrokerEvent suitable to be used for STARTED status event
- Loading branch information
1 parent
b5b187e
commit d9c210b
Showing
9 changed files
with
177 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...se/che/workspace/infrastructure/kubernetes/wsplugins/events/BrokerStatusListenerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* Copyright (c) 2012-2018 Red Hat, Inc. | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Red Hat, Inc. - initial API and implementation | ||
*/ | ||
package org.eclipse.che.workspace.infrastructure.kubernetes.wsplugins.events; | ||
|
||
import static java.util.Collections.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoMoreInteractions; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
import org.eclipse.che.api.workspace.server.spi.InfrastructureException; | ||
import org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException; | ||
import org.eclipse.che.api.workspace.server.wsplugins.model.ChePlugin; | ||
import org.eclipse.che.api.workspace.shared.dto.BrokerStatus; | ||
import org.mockito.Mock; | ||
import org.mockito.testng.MockitoTestNGListener; | ||
import org.testng.annotations.BeforeMethod; | ||
import org.testng.annotations.Listeners; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* Tests {@link BrokerStatusListener}. | ||
* | ||
* @author Sergii Leshchenko | ||
*/ | ||
@Listeners(MockitoTestNGListener.class) | ||
public class BrokerStatusListenerTest { | ||
|
||
public static final String WORKSPACE_ID = "workspace123"; | ||
@Mock private CompletableFuture<List<ChePlugin>> finishFuture; | ||
|
||
private BrokerStatusListener brokerStatusListener; | ||
|
||
@BeforeMethod | ||
public void setUp() { | ||
brokerStatusListener = new BrokerStatusListener(WORKSPACE_ID, finishFuture); | ||
} | ||
|
||
@Test | ||
public void shouldDoNothingIfEventWithForeignWorkspaceIdIsReceived() { | ||
// given | ||
BrokerEvent event = new BrokerEvent().withWorkspaceId("foreignWorkspace"); | ||
|
||
// when | ||
brokerStatusListener.onEvent(event); | ||
|
||
// then | ||
verifyNoMoreInteractions(finishFuture); | ||
} | ||
|
||
@Test | ||
public void shouldDoNothingWhenStartedEventIsReceived() { | ||
// given | ||
BrokerEvent event = | ||
new BrokerEvent().withWorkspaceId(WORKSPACE_ID).withStatus(BrokerStatus.STARTED); | ||
|
||
// when | ||
brokerStatusListener.onEvent(event); | ||
|
||
// then | ||
verifyNoMoreInteractions(finishFuture); | ||
} | ||
|
||
@Test | ||
public void shouldCompleteFinishFutureWhenDoneEventIsReceivedAndToolingIsNotNull() { | ||
// given | ||
BrokerEvent event = | ||
new BrokerEvent() | ||
.withWorkspaceId(WORKSPACE_ID) | ||
.withStatus(BrokerStatus.DONE) | ||
.withTooling(emptyList()); | ||
|
||
// when | ||
brokerStatusListener.onEvent(event); | ||
|
||
// then | ||
verify(finishFuture).complete(emptyList()); | ||
} | ||
|
||
@Test | ||
public void shouldCompleteExceptionallyFinishFutureWhenDoneEventIsReceivedButToolingIsNull() { | ||
// given | ||
BrokerEvent event = | ||
new BrokerEvent() | ||
.withWorkspaceId(WORKSPACE_ID) | ||
.withStatus(BrokerStatus.DONE) | ||
.withTooling(null); | ||
|
||
// when | ||
brokerStatusListener.onEvent(event); | ||
|
||
// then | ||
verify(finishFuture).completeExceptionally(any(InternalInfrastructureException.class)); | ||
} | ||
|
||
@Test | ||
public void shouldCompleteExceptionallyFinishFutureWhenFailedEventIsReceived() { | ||
// given | ||
BrokerEvent event = | ||
new BrokerEvent() | ||
.withWorkspaceId(WORKSPACE_ID) | ||
.withStatus(BrokerStatus.FAILED) | ||
.withError("error"); | ||
|
||
// when | ||
brokerStatusListener.onEvent(event); | ||
|
||
// then | ||
verify(finishFuture).completeExceptionally(any(InfrastructureException.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.