Package org.openstack4j.api
Class AbstractTest
- java.lang.Object
-
- org.openstack4j.api.AbstractTest
-
- Direct Known Subclasses:
ActionServiceTest,ActionTests,AlarmTests,AlarmTests,AvailabilityZoneTests,BuildInfoServiceTest,CapabilitiesTest,CapabilitiesV3Test,ClusterPolicyServiceTest,ClusterServiceTest,ClusterTests,ContainerTests,CustomEndpointURLResolverTest,CustomEndpointURLResolverTest,DBDatabaseServiceImplTest,DBDatastoreServiceImplTest,DBFlavorServiceImplTest,DBInstanceServiceImplTest,DBUserServiceImplTest,DeploymentTests,DesignateRecordsetServiceTest,DesignateZoneServiceTest,EnvironmentTests,EventServiceTest,EventTests,ExtensionTests,ExternalPolicyServiceTest,ExternalSegmentServiceTest,FirewallPolicyTests,FirewallRuleTests,FirewallTests,FlavorTests,FloatingIPTests,GroupServiceTest,HealthMonitorTests,HealthMonitorV2Tests,HealthMonitorV2Tests,HostAggregateTests,ImageTests,ImageV1Tests,ImageV2Tests,InstanceActionsTests,KeystoneAuthenticationTests,KeystoneCredentialServiceTests,KeystoneDomainServiceTests,KeystoneGroupServiceTests,KeystonePolicyServiceTest,KeystoneProjectServiceTests,KeystoneRegionServiceTest,KeystoneRoleServiceTests,KeystoneServiceEndpointServiceTest,KeystoneTests,KeystoneTokenlessTest,KeystoneUserServiceTests,L2policyServiceTest,L3policyServiceTest,LbPoolTests,LbPoolV2Tests,LbPoolV2Tests,ListenerV2Tests,ListenerV2Tests,LoadBalancerV2Tests,LoadBalancerV2Tests,MagnumTests,MemberTests,MemberV2Tests,MemberV2Tests,MeterSampleTests,MicroVersionedServiceTest,MigrationTests,NatPoolServiceTest,NetFloatingIPServiceTests,NetQosBandwidthLimitRuleTests,NetQosPolicyTests,NetQuotaTest,NetworkIPAvailabilityTest,NetworkPolicyServiceTest,NetworkTests,NeutronTagTests,NodeServiceTest,NovaHostTests,ObjectStorageTests,PolicyActionServiceTest,PolicyClassifierServiceTest,PolicyRuleServiceTest,PolicyRuleSetServiceTest,PolicyServiceTest,PolicyTargetServiceTest,PolicyTypeServiceTest,PortForwardingTests,PortTests,ProfileServiceTest,ProfileTypeServiceTest,QuotaSetTests,QuotaSetTests,ReceiverServiceTest,ResourcesTests,ResourceTest,ResourceV3Test,SampleTests,SampleV3Tests,SchedulerStatsGetPoolTests,SchedulerStatsTests,SecretTests,SecurityGroupTests,SecurityServiceTests,ServerTagTests,ServerTests,ServicechainServiceTest,ServiceFunctionChainTests,ServiceProfileServiceTest,ServicesTests,ServiceTests,ServiceTests,ServiceVersionTests,SessionTests,ShareInstanceTests,ShareNetworkTests,ShareServerTests,ShareSnapshotTests,SharesTests,ShareTests,ShareTypeTests,StackServiceTests,SubnetTests,TackerVimTests,TackerVnfdTests,TackerVnfTests,ToscaTemplatesArtifactTests,TrunkTests,VersionServiceTest,VipTests,VolumeBackupTests,VolumeSnapshotTests,VolumeTests,VolumeTypeQuotaTests,VolumeTypeTests,WebHookServiceTest,WorkflowBaseTest
public abstract class AbstractTest extends Object
Base Test class which handles Mocking a Webserver to fullfill and test against JSON response objects from an OpenStack deployment- Author:
- Jeremy Unruh
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractTest.Service
-
Field Summary
Fields Modifier and Type Field Description protected static StringJSON_ACCESSprotected static StringJSON_TOKENprotected OSClient.OSClientV2osv2protected OSClient.OSClientV3osv3protected okhttp3.mockwebserver.MockWebServerserverprotected static StringTOKEN_ID
-
Constructor Summary
Constructors Constructor Description AbstractTest()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidafterTest()protected voidassociateClientV2(OSClient.OSClientV2 osv2)protected voidassociateClientV3(OSClient.OSClientV3 osv3)protected StringauthURL(String path)protected StringgetResource(String resource)protected OSClient.OSClientV2osv2()protected OSClient.OSClientV3osv3()protected voidrespondWith(int statusCode)Responds with specified status code and no bodyprotected voidrespondWith(int statusCode, String jsonBody)Responds with specified status code and json bodyprotected voidrespondWith(String resource)Responds with success status code and body from json resource fileprotected voidrespondWith(Map<String,String> headers, int statusCode)Responds with specified status code, no body and optional headersprotected voidrespondWith(Map<String,String> headers, int statusCode, String body)Responds with specified status code, body and optional headersprotected voidrespondWithCodeAndResource(int statusCode, String resource)protected voidrespondWithHeaderAndResource(Map<String,String> headers, int statusCode, String resource)Responds with given header, status code, body from json resource file.protected abstract AbstractTest.Serviceservice()protected voidstartServer()protected okhttp3.mockwebserver.RecordedRequesttakeRequest()Awaits, removes and returns the next request made to the mock server.
-
-
-
Field Detail
-
JSON_ACCESS
protected static final String JSON_ACCESS
- See Also:
- Constant Field Values
-
JSON_TOKEN
protected static final String JSON_TOKEN
- See Also:
- Constant Field Values
-
TOKEN_ID
protected static final String TOKEN_ID
- See Also:
- Constant Field Values
-
osv2
protected OSClient.OSClientV2 osv2
-
osv3
protected OSClient.OSClientV3 osv3
-
server
protected okhttp3.mockwebserver.MockWebServer server
-
-
Method Detail
-
service
protected abstract AbstractTest.Service service()
- Returns:
- the service the API is using
-
startServer
@BeforeClass protected void startServer() throws UnknownHostException- Throws:
UnknownHostException
-
respondWith
protected void respondWith(String resource) throws IOException
Responds with success status code and body from json resource file- Parameters:
resource- the json resource file- Throws:
IOException- Signals that an I/O exception has occurred.
-
respondWith
protected void respondWith(int statusCode)
Responds with specified status code and no body- Parameters:
statusCode- the status code to respond with
-
respondWith
protected void respondWith(Map<String,String> headers, int statusCode)
Responds with specified status code, no body and optional headers- Parameters:
headers- optional headersstatusCode- the status code to respond with
-
respondWith
protected void respondWith(int statusCode, String jsonBody)Responds with specified status code and json body- Parameters:
statusCode- the status code to respond withjsonBody- the json body
-
respondWith
protected void respondWith(Map<String,String> headers, int statusCode, String body)
Responds with specified status code, body and optional headers- Parameters:
headers- optional headersstatusCode- the status code to respond withbody- the response body
-
respondWithHeaderAndResource
protected void respondWithHeaderAndResource(Map<String,String> headers, int statusCode, String resource) throws IOException
Responds with given header, status code, body from json resource file.- Parameters:
headers- the specified headerstatusCode- the status code to respond withresource- the json resource file- Throws:
IOException- Signals that an I/O exception has occurred
-
respondWithCodeAndResource
protected void respondWithCodeAndResource(int statusCode, String resource) throws IOException- Throws:
IOException
-
takeRequest
protected okhttp3.mockwebserver.RecordedRequest takeRequest() throws InterruptedExceptionAwaits, removes and returns the next request made to the mock server. Callers should use this to verify the request was sent as intended. This method will block until the request is available, possibly forever.
Be aware that this method will catch all the previous requests made to the mock server, also from other previous tests! Make sure to take all the requests made by methods in the same test class.- Returns:
- the head of the request queue
- Throws:
InterruptedException
-
afterTest
@AfterClass(alwaysRun=true) protected void afterTest()
-
associateClientV2
protected void associateClientV2(OSClient.OSClientV2 osv2)
-
associateClientV3
protected void associateClientV3(OSClient.OSClientV3 osv3)
-
osv2
protected OSClient.OSClientV2 osv2()
-
osv3
protected OSClient.OSClientV3 osv3()
-
getResource
protected String getResource(String resource) throws IOException
- Throws:
IOException
-
-