concept remote component in category java

appears as: remote components, remote component, The remote component
Testing Java Microservices: Using Arquillian, Hoverfly, AssertJ, JUnit, Selenium, and Mockito

This is an excerpt from Manning's book Testing Java Microservices: Using Arquillian, Hoverfly, AssertJ, JUnit, Selenium, and Mockito.

Solitary unit testing should focus on the interaction around a single object class. The test should encompass only the class’s own dependents or dependencies on the class. You’ll usually test resource, persistence, and remote components using solitary tests, because those components rarely need to collaborate with each other; see figure 1.12.

4.9.1. Testing the remote component

The remote component is where your microservice domain component touches anything that could be considered a remote resource. This wouldn’t include something as complex as a remote database, because that dwells in the persistence scope and is masked by the ORM layer or some other conventional API. Think more along the lines of something for which you specifically have to write the client access code—your own remote API.

You’re looking to test the interactions between your microservice domain component and the remote component; not the remote component to the actual remote resource—that would be considered a contract test, which is covered in chapter 6. In a component test, you’re not allowed to make calls outside of the local machine.

Listing 4.11. Test for the remote component
...
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo;
...
public abstract class ArquillianAbstractTest {

    @Before
    public void before() {
        stubFor(get(anyUrl()).withQueryParam("search", equalTo          #1
                ("The" + " Legend of Zelda: Breath of the Wild"))       #1
                .willReturn(aResponse().withStatus(200).withHeader      #1
                        ("Content-Type", "application/json")            #1
                        .withBody("[{\"id\":7346,\"name\":\"The " +     #1
                                "Legend of Zelda: Breath of the " +     #1
                                "Wild\"}]")));                          #1
    }

    @Rule                                                               #2
    public WireMockRule wireMockRule = new WireMockRule(8071);

    public static WebArchive createBaseDeployment(final String name) {  #3
        return ShrinkWrap.create(WebArchive.class, name + ".war")
                .addClasses(GamesResource.class,
                        ExecutorServiceProducer.class, GamesService
                                .class, IgdbGateway.class,
                        SearchResult.class, Games.class, Game
                                .class, ReleaseDate.class)
                .addAsResource("test-persistence.xml",
                        "META-INF/persistence.xml")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans" +
                        ".xml");
    }
}