org.junit.experimental.theories.FromDataPoints Java Examples

The following examples show how to use org.junit.experimental.theories.FromDataPoints. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WhatCommandIT.java    From emissary with Apache License 2.0 6 votes vote down vote up
@Theory
public void verifyExpectedOptions(@FromDataPoints("ProjectBase Options") String baseDirArg, @FromDataPoints("Input Options") String inputDirArg,
        @FromDataPoints("String Options") String stringArg, @FromDataPoints("Boolean Options Without Value") String booleanArgWithoutValue,
        @FromDataPoints("Boolean Options With Value") String booleanArgWithValue) throws Exception {
    // setup
    arguments.add(baseDirArg);
    arguments.add(baseDir.toString());
    arguments.add(inputDirArg);
    arguments.add(inputDir.toString());
    arguments.add(stringArg);
    arguments.add("validateStringArg");
    arguments.add(booleanArgWithoutValue);
    arguments.add(booleanArgWithValue);
    arguments.add(Boolean.FALSE.toString());

    // test (no exceptions thrown)
    WhatCommand.parse(WhatCommand.class, arguments);
}
 
Example #2
Source File: FeedCommandIT.java    From emissary with Apache License 2.0 6 votes vote down vote up
@Theory
public void verifyExpectedOptions(@FromDataPoints("ProjectBase Options") String baseDirArg, @FromDataPoints("Input Options") String inputDirArg,
        @FromDataPoints("String Options") String stringArg, @FromDataPoints("Boolean Options") String booleanArg,
        @FromDataPoints("Int Options") String intArg) throws Exception {
    // setup
    arguments.add(baseDirArg);
    arguments.add(baseDir.toString());
    arguments.add(inputDirArg);
    arguments.add(inputDir.toString());
    arguments.add(stringArg);
    arguments.add("validateStringArg");
    arguments.add(booleanArg);
    arguments.add(intArg);
    arguments.add("4");

    // verify (no exceptions thrown)
    FeedCommand.parse(FeedCommand.class, arguments);
}
 
Example #3
Source File: AndroidManifestValidatorTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
@Theory
public void assetModule_withSdkConstraint_throws(
    @FromDataPoints("sdkMutators") ManifestMutator sdkMutator) throws Exception {
  BundleModule module =
      new BundleModuleBuilder("asset_module")
          .setManifest(androidManifestForAssetModule("com.test.app", sdkMutator))
          .build();

  InvalidBundleException exception =
      assertThrows(
          InvalidBundleException.class,
          () -> new AndroidManifestValidator().validateModule(module));
  assertThat(exception)
      .hasMessageThat()
      .matches("Unexpected element declaration in manifest of asset pack 'asset_module'.");
}
 
Example #4
Source File: InstallApksCommandTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
@Theory
public void badDensityDevice_throws(@FromDataPoints("apksInDirectory") boolean apksInDirectory)
    throws Exception {
  Path apksFile =
      createApks(createSimpleTableOfContent(ZipPath.create("base-master.apk")), apksInDirectory);

  DeviceSpec deviceSpec =
      mergeSpecs(sdkVersion(21), density(-1), abis("x86_64", "x86"), locales("en-US"));
  FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
  AdbServer adbServer =
      new FakeAdbServer(/* hasInitialDeviceList= */ true, ImmutableList.of(fakeDevice));

  InstallApksCommand command =
      InstallApksCommand.builder()
          .setApksArchivePath(apksFile)
          .setAdbPath(adbPath)
          .setAdbServer(adbServer)
          .build();

  Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
  assertThat(exception).hasMessageThat().contains("Error retrieving device density");
}
 
Example #5
Source File: InstallApksCommandTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
@Theory
public void badAbisDevice_throws(@FromDataPoints("apksInDirectory") boolean apksInDirectory)
    throws Exception {
  Path apksFile =
      createApks(createSimpleTableOfContent(ZipPath.create("base-master.apk")), apksInDirectory);

  DeviceSpec deviceSpec = mergeSpecs(sdkVersion(21), density(480), abis(), locales("en-US"));
  FakeDevice fakeDevice = FakeDevice.fromDeviceSpec(DEVICE_ID, DeviceState.ONLINE, deviceSpec);
  AdbServer adbServer =
      new FakeAdbServer(/* hasInitialDeviceList= */ true, ImmutableList.of(fakeDevice));

  InstallApksCommand command =
      InstallApksCommand.builder()
          .setApksArchivePath(apksFile)
          .setAdbPath(adbPath)
          .setAdbServer(adbServer)
          .build();

  Throwable exception = assertThrows(IllegalStateException.class, () -> command.execute());
  assertThat(exception).hasMessageThat().contains("Error retrieving device ABIs");
}
 
Example #6
Source File: BuildApksDeviceSpecTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
@Theory
public void deviceSpec_systemApkMode_partialDeviceSpecMissingDensity_throws(
    @FromDataPoints("systemApkBuildModes") ApkBuildMode systemApkBuildMode) throws Exception {
  DeviceSpec deviceSpec = mergeSpecs(abis("arm64-v8a"));

  AppBundle appBundle =
      new AppBundleBuilder()
          .addModule("base", module -> module.setManifest(androidManifest("com.app")))
          .build();
  bundleSerializer.writeToDisk(appBundle, bundlePath);

  BuildApksCommand.Builder command =
      BuildApksCommand.builder()
          .setBundlePath(bundlePath)
          .setOutputFile(outputFilePath)
          .setDeviceSpec(deviceSpec)
          .setApkBuildMode(systemApkBuildMode);

  Throwable exception = assertThrows(InvalidCommandException.class, command::build);
  assertThat(exception)
      .hasMessageThat()
      .contains(
          "Device spec must have screen density and ABIs set when running with 'system' or "
              + "'system_compressed' mode flag.");
}
 
Example #7
Source File: BuildApksDeviceSpecTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
@Theory
public void deviceSpec_systemApkMode_partialDeviceSpecWithAbiAndScreenDensity_succeeds(
    @FromDataPoints("systemApkBuildModes") ApkBuildMode systemApkBuildMode) throws Exception {
  DeviceSpec deviceSpec = mergeSpecs(abis("arm64-v8a"), density(DensityAlias.MDPI));

  AppBundle appBundle =
      new AppBundleBuilder()
          .addModule("base", module -> module.setManifest(androidManifest("com.app")))
          .build();
  bundleSerializer.writeToDisk(appBundle, bundlePath);

  BuildApksCommand.Builder command =
      BuildApksCommand.builder()
          .setBundlePath(bundlePath)
          .setOutputFile(outputFilePath)
          .setDeviceSpec(deviceSpec)
          .setApkBuildMode(systemApkBuildMode);

  command.build();
}
 
Example #8
Source File: CredHubCredentialTemplateSummaryUnitTests.java    From spring-credhub with Apache License 2.0 6 votes vote down vote up
@Theory
public void findByPath(@FromDataPoints("responses") ResponseEntity<CredentialSummaryData> expectedResponse) {
	given(this.restTemplate.getForEntity(CredHubCredentialTemplate.PATH_URL_QUERY, CredentialSummaryData.class,
			NAME.getName())).willReturn(expectedResponse);

	if (!expectedResponse.getStatusCode().equals(HttpStatus.OK)) {
		try {
			this.credHubTemplate.findByPath(NAME.getName());
			fail("Exception should have been thrown");
		}
		catch (CredHubException ex) {
			assertThat(ex.getMessage()).contains(expectedResponse.getStatusCode().toString());
		}
	}
	else {
		List<CredentialSummary> response = this.credHubTemplate.findByPath(NAME.getName());

		assertResponseContainsExpectedCredentials(expectedResponse, response);
	}
}
 
Example #9
Source File: BuildApksDeviceSpecTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
@Theory
public void deviceSpec_systemApkMode_withoutDeviceSpec_throws(
    @FromDataPoints("systemApkBuildModes") ApkBuildMode systemApkBuildMode) throws Exception {
  AppBundle appBundle =
      new AppBundleBuilder()
          .addModule("base", module -> module.setManifest(androidManifest("com.app")))
          .build();
  bundleSerializer.writeToDisk(appBundle, bundlePath);

  BuildApksCommand.Builder command =
      BuildApksCommand.builder()
          .setBundlePath(bundlePath)
          .setOutputFile(outputFilePath)
          .setApkBuildMode(systemApkBuildMode);

  Throwable exception = assertThrows(InvalidCommandException.class, command::build);
  assertThat(exception)
      .hasMessageThat()
      .contains(
          "Device spec must always be set when running with 'system' or 'system_compressed' "
              + "mode flag.");
}
 
Example #10
Source File: GetSizeCommandTest.java    From bundletool with Apache License 2.0 6 votes vote down vote up
@Test
@Theory
public void checkFlagsConstructionWithDeviceSpec(
    @FromDataPoints("deviceSpecs") String deviceSpecPath) throws Exception {
  DeviceSpec.Builder expectedDeviceSpecBuilder = DeviceSpec.newBuilder();
  try (Reader reader = TestData.openReader(deviceSpecPath)) {
    JsonFormat.parser().merge(reader, expectedDeviceSpecBuilder);
  }
  DeviceSpec expectedDeviceSpec = expectedDeviceSpecBuilder.build();

  BuildApksResult tableOfContentsProto = BuildApksResult.getDefaultInstance();
  Path apksArchiveFile =
      createApksArchiveFile(tableOfContentsProto, tmpDir.resolve("bundle.apks"));
  Path deviceSpecFile = copyToTempDir(deviceSpecPath);

  GetSizeCommand command =
      GetSizeCommand.fromFlags(
          new FlagParser()
              .parse(
                  "get-size",
                  "total",
                  "--device-spec=" + deviceSpecFile,
                  "--apks=" + apksArchiveFile));

  assertThat(command.getDeviceSpec()).isEqualTo(expectedDeviceSpec);
}
 
Example #11
Source File: ExtractApksCommandTest.java    From bundletool with Apache License 2.0 5 votes vote down vote up
@Test
@Theory
public void oneModule_Ldevice_matchesLmasterSplit(
    @FromDataPoints("apksInDirectory") boolean apksInDirectory) throws Exception {
  ZipPath apkOne = ZipPath.create("apk_one.apk");
  BuildApksResult tableOfContentsProto =
      BuildApksResult.newBuilder()
          .setBundletool(
              Bundletool.newBuilder()
                  .setVersion(BundleToolVersion.getCurrentVersion().toString()))
          .addVariant(
              createVariantForSingleSplitApk(
                  variantSdkTargeting(sdkVersionFrom(21)),
                  ApkTargeting.getDefaultInstance(),
                  apkOne))
          .build();
  Path apksPath = createApks(tableOfContentsProto, apksInDirectory);

  DeviceSpec deviceSpec = deviceWithSdk(21);

  ExtractApksCommand.Builder extractedApksCommand =
      ExtractApksCommand.builder().setApksArchivePath(apksPath).setDeviceSpec(deviceSpec);
  if (!apksInDirectory) {
    extractedApksCommand.setOutputDirectory(tmpDir);
  }
  ImmutableList<Path> matchedApks = extractedApksCommand.build().execute();

  if (apksInDirectory) {
    assertThat(matchedApks).containsExactly(inTempDirectory(apkOne.toString()));
  } else {
    assertThat(matchedApks).containsExactly(inOutputDirectory(apkOne.getFileName()));
  }
  for (Path matchedApk : matchedApks) {
    checkFileExistsAndReadable(tmpDir.resolve(matchedApk));
  }
}
 
Example #12
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToServiceTalkErrorInResponseNoOffload(@FromDataPoints("ssl") final boolean ssl,
                                                          @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE_IN_RESPONSE, ssl, noOffloadsStrategy());
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testGrpcError(client, server, false, streaming);
}
 
Example #13
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToGrpcJava(@FromDataPoints("ssl") final boolean ssl,
                               @FromDataPoints("streaming") final boolean streaming) throws Exception {
    final TestServerContext server = grpcJavaServer(ErrorMode.NONE, ssl);
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testRequestResponse(client, server, streaming);
}
 
Example #14
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToServiceTalk(@FromDataPoints("ssl") final boolean ssl,
                                  @FromDataPoints("streaming") final boolean streaming) throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.NONE, ssl);
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testRequestResponse(client, server, streaming);
}
 
Example #15
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Ignore("gRPC compression not supported by ServiceTalk yet")
@Theory
public void grpcJavaToServiceTalkCompressedGzip(@FromDataPoints("ssl") final boolean ssl,
                                                @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.NONE, ssl);
    // Only gzip is supported by GRPC out of the box atm.
    final CompatClient client = grpcJavaClient(server.listenAddress(), "gzip", ssl);
    testRequestResponse(client, server, streaming);
}
 
Example #16
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void serviceTalkToServiceTalk(@FromDataPoints("ssl") final boolean ssl,
                                     @FromDataPoints("streaming") final boolean streaming) throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.NONE, ssl);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl);
    testRequestResponse(client, server, streaming);
}
 
Example #17
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void serviceTalkToServiceTalkErrorWithStatusViaServerFilter(
        @FromDataPoints("ssl") final boolean ssl, @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.STATUS_IN_SERVER_FILTER, ssl);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl);
    testGrpcError(client, server, true, streaming);
}
 
Example #18
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToGrpcJavaErrorWithStatus(@FromDataPoints("ssl") final boolean ssl,
                                              @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = grpcJavaServer(ErrorMode.STATUS, ssl);
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testGrpcError(client, server, true, streaming);
}
 
Example #19
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToServiceTalkErrorInScalarResponse(@FromDataPoints("ssl") final boolean ssl)
        throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE_IN_RESPONSE, ssl);
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testGrpcError(client, server, false, false);
}
 
Example #20
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void serviceTalkToGrpcJavaErrorWithStatus(@FromDataPoints("ssl") final boolean ssl,
                                                 @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = grpcJavaServer(ErrorMode.STATUS, ssl);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl);
    testGrpcError(client, server, true, streaming);
}
 
Example #21
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToServiceTalkErrorViaServiceFilter(@FromDataPoints("ssl") final boolean ssl,
                                                       @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE_IN_SERVICE_FILTER, ssl);
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testGrpcError(client, server, false, streaming);
}
 
Example #22
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void serviceTalkToServiceTalkErrorViaServerFilter(@FromDataPoints("ssl") final boolean ssl,
                                                         @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE_IN_SERVER_FILTER, ssl);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl);
    testGrpcError(client, server, false, streaming);
}
 
Example #23
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void serviceTalkToServiceTalkErrorViaServiceFilter(@FromDataPoints("ssl") final boolean ssl,
                                                          @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE_IN_SERVICE_FILTER, ssl);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl);
    testGrpcError(client, server, false, streaming);
}
 
Example #24
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToServiceTalkErrorWithStatusInScalarResponse(@FromDataPoints("ssl") final boolean ssl)
        throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.STATUS_IN_RESPONSE, ssl);
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testGrpcError(client, server, true, false);
}
 
Example #25
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToServiceTalkErrorWithStatusInResponseNoOffloads(
        @FromDataPoints("ssl") final boolean ssl,
        @FromDataPoints("streaming") final boolean streaming) throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.STATUS_IN_RESPONSE, ssl, noOffloadsStrategy());
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testGrpcError(client, server, true, streaming);
}
 
Example #26
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToServiceTalkBlocking(@FromDataPoints("ssl") final boolean ssl,
                                          @FromDataPoints("streaming") final boolean streaming) throws Exception {
    final TestServerContext server = serviceTalkServerBlocking(ErrorMode.NONE, ssl);
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testRequestResponse(client, server, streaming);
}
 
Example #27
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToServiceTalkBlockingError(@FromDataPoints("ssl") final boolean ssl,
                                               @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = serviceTalkServerBlocking(ErrorMode.SIMPLE, ssl);
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testGrpcError(client, server, false, streaming);
}
 
Example #28
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void grpcJavaToServiceTalkBlockingErrorWithStatus(@FromDataPoints("ssl") final boolean ssl,
                                                         @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = serviceTalkServerBlocking(ErrorMode.STATUS, ssl);
    final CompatClient client = grpcJavaClient(server.listenAddress(), null, ssl);
    testGrpcError(client, server, true, streaming);
}
 
Example #29
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void serviceTalkToServiceTalkError(@FromDataPoints("ssl") final boolean ssl,
                                          @FromDataPoints("streaming") final boolean streaming) throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.SIMPLE, ssl);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl);
    testGrpcError(client, server, false, streaming);
}
 
Example #30
Source File: ProtocolCompatibilityTest.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
@Theory
public void serviceTalkToServiceTalkErrorWithStatus(@FromDataPoints("ssl") final boolean ssl,
                                                    @FromDataPoints("streaming") final boolean streaming)
        throws Exception {
    final TestServerContext server = serviceTalkServer(ErrorMode.STATUS, ssl);
    final CompatClient client = serviceTalkClient(server.listenAddress(), ssl);
    testGrpcError(client, server, true, streaming);
}