I have a viewpager and it contains a fragment. In my application there are two tabs and fragments are changing according to tab switch.
When I want to check that the correct fragment is opened in the tab change, I get the following error because code can't find the fragment inside the viewpager.
Error part is:
java.lang.RuntimeException: java.lang.NullPointerException: Cannot run onActivity since Activity has been destroyed already
at androidx.test.runner.MonitoringInstrumentation.runOnMainSync(MonitoringInstrumentation.java:450)
at androidx.test.core.app.ActivityScenario.onActivity(ActivityScenario.java:673)
at dashboard.test.DashboardNavigationTests$CheckBothTabsAreSwitchable$1$3.invoke(DashboardNavigationTests.kt:136)
at dashboard.test.DashboardNavigationTests$CheckBothTabsAreSwitchable$1$3.invoke(DashboardNavigationTests.kt:135)
at com.kaspersky.kaspresso.testcases.core.testcontext.TestContext.step(TestContext.kt:39)
at dashboard.test.DashboardNavigationTests$CheckBothTabsAreSwitchable$1.invoke(DashboardNavigationTests.kt:135)
at dashboard.test.DashboardNavigationTests$CheckBothTabsAreSwitchable$1.invoke(DashboardNavigationTests.kt:126)
at com.kaspersky.kaspresso.testcases.core.TestRunner.runMainTestSection(TestRunner.kt:144)
at com.kaspersky.kaspresso.testcases.core.TestRunner.run(TestRunner.kt:58)
at com.kaspersky.kaspresso.testcases.core.sections.MainTestSection.run(MainTestSection.kt:29)
at com.kaspersky.kaspresso.testcases.api.testcase.BaseTestCase.run(BaseTestCase.kt:90)
at com.kaspersky.kaspresso.testcases.api.testcase.BaseTestCase.run$default(BaseTestCase.kt:86)
at dashboard.test.DashboardNavigationTests.CheckBothTabsAreSwitchable(DashboardNavigationTests.kt:126)
at java.lang.reflect.Method.invoke(Native Method)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at androidx.test.internal.runner.junit4.statement.RunBefores.evaluate(RunBefores.java:80)
at androidx.test.internal.runner.junit4.statement.RunAfters.evaluate(RunAfters.java:61)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:27)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
at androidx.test.internal.runner.TestExecutor.execute(TestExecutor.java:56)
at androidx.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:395)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2205)
Caused by: java.lang.NullPointerException: Cannot run onActivity since Activity has been destroyed already
at androidx.test.internal.util.Checks.checkNotNull(Checks.java:41)
at androidx.test.core.app.ActivityScenario.lambda$onActivity$2$ActivityScenario(ActivityScenario.java:658)
at androidx.test.core.app.ActivityScenario$$Lambda$4.run(Unknown Source:4)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:462)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at android.app.Instrumentation$SyncRunnable.run(Instrumentation.java:2223)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7656)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
And my code block is
#Test
fun CheckBothTabsAreSwitchableAndVerifyFragments() = run {
step("Navigate to Dashboard") {
this#DashboardNavigationTests.NavigateToWelcomePageToDashboard()
}
step("click map tab") {
dashboardScreen.clickMapTab()
}
step("check current fragment is dashboard fragment ") {
activityScenario?.onActivity {
val nextFragment = it.getLastFragment()
assertTrue(nextFragment::class.java == DetectionMapFragment::class.java)
}
}
step("click detection tab") {
dashboardScreen.clickDetectionsTab()
}
step("check current fragment is dashboard fragment") {
activityScenario?.onActivity {
val nextFragment = it.getLastFragment()
assertTrue(nextFragment::class.java == DashboardFragment::class.java)
}
}
}
Could you help me to find fragment in viewpager?
Thank you for your guidance.
Related
Using Zulu JDK (8u242b20) in an Java application, I'm receiving an exception when trying to run a test from a kotlin class as follows:
class SomeTest {
#MockK
private lateinit var fileService: FileService
#SetUp
fun setUp(){
MockKAnnotations.init(this, relaxed = true)
}
#Test
fun `foo`(){
// do something
}
}
The exception is as follows
java.lang.ExceptionInInitializerError
at com.something.SomeTest.setUp(SomeTest.kt:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.IllegalStateException: Error during attachment using: net.bytebuddy.agent.ByteBuddyAgent$AttachmentProvider$Compound#6156496
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:384)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:358)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:326)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:312)
at io.mockk.proxy.jvm.JvmMockKAgentFactory.initInstrumentation(JvmMockKAgentFactory.kt:127)
at io.mockk.proxy.jvm.JvmMockKAgentFactory.init(JvmMockKAgentFactory.kt:34)
at io.mockk.impl.JvmMockKGateway.<init>(JvmMockKGateway.kt:46)
at io.mockk.impl.JvmMockKGateway.<clinit>(JvmMockKGateway.kt:169)
... 23 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at net.bytebuddy.agent.Attacher.install(Attacher.java:84)
at net.bytebuddy.agent.ByteBuddyAgent.install(ByteBuddyAgent.java:379)
... 30 more
Caused by: com.sun.tools.attach.AttachNotSupportedException: no providers installed
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
... 36 more
java.lang.NoClassDefFoundError: Could not initialize class io.mockk.impl.JvmMockKGateway
at com.something.SomeTest.setUp(SomeTest.kt:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
It started after using MockK, using kotlin was fine before.
Any idea what could be the cause of this?
I don't know what other details to add, everything should be visible from code, but I'm still unable to post the question due to stackoverflow restrictions, so this is just generating some random blabla text.
ByteBuddy needs classes that are inside tools.jar library which is part of JDK and most probably missing from your classpath. You can add $JAVA_HOME/lib to your classpath or add the dependency with maven instead.
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
While trying to run my Karate project as Junit, I am getting the below error.
All of my slf4j dependencies in the .m2 repo looks fine. But couldn't figure out what is the issue. Could you please someone help me to get rid of this issue
java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at com.intuit.karate.Runner.<clinit>(Runner.java:51)
at soa.core.ParallelTest.testParallel(ParallelTest.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 25 more
Here is my Junit Runner class. The exception is thrown at line number 2 of testParallel() method
public class ParallelTest {
#Test
public void testParallel() {
System.setProperty("karate.env", "acpt");
Results results = Runner.parallel(getClass(), 1);
generateReport(results.getReportDir());
assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
}
public static void generateReport(String karateOutputPath) {
Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] {"json"}, true);
List<String> jsonPaths = new ArrayList(jsonFiles.size());
jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
Configuration config = new Configuration(new File("target"), "WTR_EPP");
ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
reportBuilder.generateReports();
}
}
Pretty sure you have a pom.xml that includes a bunch of other dependencies and you will need to resolve JAR / library conflicts yourself.
One suggestion is to create a quickstart project - get that working first - and then compare with the problem project you have.
If you are still stuck - please follow this process: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue
While testing LiveData through JUnit in Kotlin I am facing a weird issue in which Logs are showing expected and actual value exact similar but still Test Observer failing the test.
Below is the test and logs after running the test.
#Test
fun onSelectedAddressInfoTest_selected() {
viewModel.selectedAddressInfo?.test()?.assertNoValue()
viewModel.onAddressInfoSelected(AddressInfoStub.getValidStub())
viewModel.selectedAddressInfo?.test()?.assertHasValue()
//error is here
// viewModel.selectedAddressInfo?.test()?.assertValue(AddressInfoStub.getValidStub())
}
Output:
java.lang.AssertionError:
Expected: AddressInfo(id=1, imageUrl=image.com, description=Deliver to hukum, location=Location{address = 'place',lng = '12.999999',lat = '24.0'}) (class: AddressInfo)
Actual: AddressInfo(id=1, imageUrl=image.com, description=Deliver to hukum, location=Location{address = 'place',lng = '12.999999',lat = '24.0'}) (class: AddressInfo)
at com.jraska.livedata.TestObserver.fail(TestObserver.java:268)
at com.jraska.livedata.TestObserver.assertValue(TestObserver.java:105)
at com.assessment.AddressInfobaseproject.ui.AddressInfoList.AddressInfoListViewModelTest.onSelectedAddressInfoTest_selected(AddressInfoListViewModelTest.kt:33)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
at org.junit.rules.RunRules.evaluate(RunRules.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.mockito.internal.runners.DefaultInternalRunner$1.run(DefaultInternalRunner.java:79)
at org.mockito.internal.runners.DefaultInternalRunner.run(DefaultInternalRunner.java:85)
at org.mockito.internal.runners.StrictRunner.run(StrictRunner.java:39)
at org.mockito.junit.MockitoJUnitRunner.run(MockitoJUnitRunner.java:163)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
I'm writing a simple Spring test on Kotlin and have a compilation error with generics that I can't understand. The function is below:
#Test
fun actuatorRootReturnsOnlyAllowed() {
val expectBody:WebTestClient.BodySpec<Map<String, Map<String, Any>>, *> = client!!.get().uri("/app")
.accept(MediaType.APPLICATION_JSON_UTF8)
.exchange()
.expectStatus().isOk
.expectBody(object : ParameterizedTypeReference<Map<String, Map<String, Any>>>() {})
expectBody.consumeWith<Map<String, Map<String, Any>>> { result->
val actuatorLinks = result.responseBody!!["_links"]
Assert.assertTrue(actuatorLinks!!.containsKey("self"))
Assert.assertTrue(actuatorLinks.containsKey("health"))
Assert.assertTrue(actuatorLinks.containsKey("info"))
Assert.assertTrue(actuatorLinks.containsKey("loggers"))
Assert.assertTrue(actuatorLinks.containsKey("loggers-name"))
}
}
The problem is in line expectBody.consumeWith. For some reason Kotlin expects type Nothing with the compilation error: Error:(53, 32) Kotlin: Type argument is not within its bounds: should be subtype of 'Nothing!'.
Actual type of consumeWith method is EntityExchangeResult<T>, however method still expects Nothing. I would expect something like expectBody.consumeWithEntityExchangeResult<<Map<String, Map<String, Any>>>> or expectBody.consumeWith<Map<String, Map<String, Any>>> instead.
However with type Nothing I get the NullPointerException:
java.lang.NullPointerException
at com.example.ActuatorEndpointsTest.actuatorRootReturnsOnlyAllowed(ActuatorEndpointsTest.kt:52)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:564)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
Below is the same working equivalent in Java:
#Test
public void actuatorRootReturnsOnlyAllowed() {
client.get().uri("/app")
.accept(MediaType.APPLICATION_JSON_UTF8)
.exchange()
.expectStatus().isOk()
.expectBody(new ParameterizedTypeReference<Map<String, Map<String, Object>>>(){})
.consumeWith(result -> {
final Map<String, Object> actuatorLinks = result.getResponseBody().get("_links");
assertTrue(actuatorLinks.containsKey("self"));
assertTrue(actuatorLinks.containsKey("health"));
assertTrue(actuatorLinks.containsKey("info"));
assertTrue(actuatorLinks.containsKey("loggers"));
assertTrue(actuatorLinks.containsKey("loggers-name"));
});
}
Can anyone explain the reason why Kotlin expects Nothing and how this code can be corrected?
I want to delete service include in serviceGroup of load balancer
but it make error !!
How to delete service & serviceGroup using java API?
VirtualIpAddress.Service vipService = VirtualIpAddress.service(client, virtualIpAddressId);
vipService.clearMask();
StringBuffer maskBuffer = new StringBuffer();
maskBuffer.append("mask");
maskBuffer.append("[");
maskBuffer.append("applicationDeliveryController");
maskBuffer.append(",billingItem");
maskBuffer.append(",ipAddress");
maskBuffer.append(",loadBalancerHardware[datacenterName,location]");
maskBuffer.append(",secureTransportCiphers");
maskBuffer.append(",secureTransportProtocols");
maskBuffer.append(",virtualServers[");
maskBuffer.append(" serviceGroups[");
maskBuffer.append(" routingMethod,routingType,serviceReferences,services[");
maskBuffer.append(" groupReferences,healthChecks,ipAddress]]]");
maskBuffer.append("]");
vipService.setMask(maskBuffer.toString());
VirtualIpAddress virtualIpAddress = vipService.getObject();
List<VirtualServer> virtualServerList = virtualIpAddress.getVirtualServers();
for(VirtualServer virtualServer : virtualServerList) {
List<Group> serviceGroupList = virtualServer.getServiceGroups();
for(Group group : serviceGroupList) {
List<com.softlayer.api.service.network.application.delivery.controller.loadbalancer.LoadBalancerService> serviceList = group.getServices();
for(com.softlayer.api.service.network.application.delivery.controller.loadbalancer.LoadBalancerService service : serviceList) {
LoadBalancerService.Service loadBalancerService = LoadBalancerService.service(client, service.getId());
System.out.println("loadBalancerService : " + loadBalancerService);
serviceDelFlag = loadBalancerService.deleteObject();
}
}
}
occurring error:
serviceGroupService : Service: SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualServer with ID 234553
com.softlayer.api.ApiException$NotFound: Unable to find object with id of '234553'.(code: SoftLayer_Exception_ObjectNotFound, status: 404)
at com.softlayer.api.ApiException.fromError(ApiException.java:14)
at com.softlayer.api.RestApiClient$ServiceProxy.logAndHandleResponse(RestApiClient.java:308)
at com.softlayer.api.RestApiClient$ServiceProxy.invokeService(RestApiClient.java:359)
at com.softlayer.api.RestApiClient$ServiceProxy.invoke(RestApiClient.java:537)
at com.sun.proxy.$Proxy15.deleteObject(Unknown Source)
at com.ibm.softlayer.network.LoadBalancingTest_v1.getLoadBalancerDetail(LoadBalancingTest_v1.java:219)
at com.ibm.softlayer.network.LoadBalancingTest_v1.viewLoadBalancerList(LoadBalancingTest_v1.java:134)
at com.ibm.softlayer.network.LoadBalancingTest_v1.getLoadBalancers(LoadBalancingTest_v1.java:125)
at com.ibm.softlayer.network.LoadBalancingTest_v1.test(LoadBalancingTest_v1.java:69)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Well the ID 234553 does not exist for the object type SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualServer, that is the error.
to get the valid IDs for the object you can call the method: http://sldn.softlayer.com/reference/services/SoftLayer_Account/getAdcLoadBalancers + an object mask to list the virtual server. here an example using Restful:
GET https://api.softlayer.com/rest/v3.1/SoftLayer_Account/getAdcLoadBalancers?objectMask=mask[virtualServers]
with this method you will delete service groups
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_VirtualServer/dele
with this method you will delete services:
http://sldn.softlayer.com/reference/services/SoftLayer_Network_Application_Delivery_Controller_LoadBalancer_Service/deleteObje
Just make sure you are using the correct IDs in the methods.
If you are still having issues with the Java client let me know to write an example in java for you.
Regards