You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jclouds.apache.org by Zack Shoylev <no...@github.com> on 2013/12/10 00:18:39 UTC

[jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

This approach could/should be applied to the other expect tests.
You can merge this Pull Request by running:

  git pull https://github.com/rackerlabs/jclouds-labs-openstack mock-webserver-refactor

Or you can view, comment on it, or merge it online at:

  https://github.com/jclouds/jclouds-labs-openstack/pull/59

-- Commit Summary --

  * Sample refactoring of GroupApiExpectTest to use MockWebServer

-- File Changes --

    M rackspace-autoscale/pom.xml (6)
    D rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/GroupApiExpectTest.java (515)
    A rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/features/GroupApiMockTest.java (784)
    A rackspace-autoscale/src/test/java/org/jclouds/rackspace/autoscale/v1/internal/BaseAutoscaleApiMockTest.java (40)
    A rackspace-autoscale/src/test/resources/access.json (249)

-- Patch Links --

https://github.com/jclouds/jclouds-labs-openstack/pull/59.patch
https://github.com/jclouds/jclouds-labs-openstack/pull/59.diff

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Zack Shoylev <no...@github.com>.
> +         assertEquals(g.getLaunchConfiguration().getPersonalities().get(0).getContents(), "VGhpcyBpcyBhIHRlc3QgZmlsZS4=");
> +         assertEquals(g.getLaunchConfiguration().getNetworks().size(), 2);
> +         assertEquals(g.getLaunchConfiguration().getNetworks().get(0), "11111111-1111-1111-1111-111111111111");
> +         assertEquals(g.getLaunchConfiguration().getNetworks().get(1), "00000000-0000-0000-0000-000000000000");
> +         assertEquals(g.getLaunchConfiguration().getServerMetadata().size(), 3);
> +         assertTrue(g.getLaunchConfiguration().getServerMetadata().containsKey("build_config"));
> +         assertTrue(g.getLaunchConfiguration().getServerMetadata().containsValue("core"));
> +         assertEquals(g.getLaunchConfiguration().getType(), LaunchConfigurationType.LAUNCH_SERVER);
> +
> +         assertEquals(g.getGroupConfiguration().getMaxEntities(), 10);
> +         assertEquals(g.getGroupConfiguration().getCooldown(), 360);
> +         assertEquals(g.getGroupConfiguration().getName(), "testscalinggroup198547");
> +         assertEquals(g.getGroupConfiguration().getMinEntities(), 0);
> +         assertEquals(g.getGroupConfiguration().getMetadata().size(), 2);
> +         assertTrue(g.getGroupConfiguration().getMetadata().containsKey("gc_meta_key_2"));
> +         assertTrue(g.getGroupConfiguration().getMetadata().containsValue("gc_meta_value_2"));

Good point. I will get that done in the next round of refactoring. The result test code is mostly copy-pasta from the expect test.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59/files#r8271354

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Andrew Phillips <no...@github.com>.
> +         assertEquals(g.getLaunchConfiguration().getPersonalities().get(0).getContents(), "VGhpcyBpcyBhIHRlc3QgZmlsZS4=");
> +         assertEquals(g.getLaunchConfiguration().getNetworks().size(), 2);
> +         assertEquals(g.getLaunchConfiguration().getNetworks().get(0), "11111111-1111-1111-1111-111111111111");
> +         assertEquals(g.getLaunchConfiguration().getNetworks().get(1), "00000000-0000-0000-0000-000000000000");
> +         assertEquals(g.getLaunchConfiguration().getServerMetadata().size(), 3);
> +         assertTrue(g.getLaunchConfiguration().getServerMetadata().containsKey("build_config"));
> +         assertTrue(g.getLaunchConfiguration().getServerMetadata().containsValue("core"));
> +         assertEquals(g.getLaunchConfiguration().getType(), LaunchConfigurationType.LAUNCH_SERVER);
> +
> +         assertEquals(g.getGroupConfiguration().getMaxEntities(), 10);
> +         assertEquals(g.getGroupConfiguration().getCooldown(), 360);
> +         assertEquals(g.getGroupConfiguration().getName(), "testscalinggroup198547");
> +         assertEquals(g.getGroupConfiguration().getMinEntities(), 0);
> +         assertEquals(g.getGroupConfiguration().getMetadata().size(), 2);
> +         assertTrue(g.getGroupConfiguration().getMetadata().containsKey("gc_meta_key_2"));
> +         assertTrue(g.getGroupConfiguration().getMetadata().containsValue("gc_meta_value_2"));

Ah, like that...thanks for explaining.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59/files#r8271790

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Andrew Phillips <no...@github.com>.
> +               .maxEntities(100)
> +               .metadata(ImmutableMap.of("firstkey", "this is a string", "secondkey", "1"))
> +               .build();
> +
> +         boolean result = api.updateGroupConfiguration("1234567890", gc);
> +
> +         /*
> +          * Check request
> +          */
> +         assertAuthentication(server);
> +         assertRequest(server.takeRequest(), "PUT", "/v1.0/888888/groups/1234567890/config", "/autoscale_groups_update_configuration_request.json");
> +
> +         /*
> +          * Check response
> +          */
> +         assertTrue(result);

Use either `result` or `success` throughout the tests for the boolean return value of the API call?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59/files#r8266378

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Andrew Phillips <no...@github.com>.
A couple of small after-the-fact comments, but otherwise looks good - thanks, @zack-shoylev!

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30321138

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Andrew Phillips <no...@github.com>.
> +         assertRequest(server.takeRequest(), "GET", "/v1.0/888888/groups");
> +
> +         /*
> +          * Check response
> +          */
> +         assertEquals(groupStates.size(),2);
> +
> +         assertEquals(groupStates.get(0).getGroupInstances().size(), 0);
> +         assertEquals(groupStates.get(0).getActiveCapacity(), 0);
> +         assertEquals(groupStates.get(0).getDesiredCapacity(), 0);
> +         assertEquals(groupStates.get(0).getId(), "e41380ae-173c-4b40-848a-25c16d7fa83d");
> +         assertEquals(groupStates.get(0).getLinks().size(), 1);
> +         assertEquals(groupStates.get(0).getLinks().get(0).getHref().toString(), "https://dfw.autoscale.api.rackspacecloud.com/v1.0/676873/groups/e41380ae-173c-4b40-848a-25c16d7fa83d/");
> +         assertEquals(groupStates.get(0).getLinks().get(0).getRelation(), Link.Relation.SELF);
> +         assertEquals(groupStates.get(0).getPaused(), false);
> +         assertEquals(groupStates.get(0).getPendingCapacity(), 0);

Same comment as above about comparing the group state here.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59/files#r8266329

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Andrew Phillips <no...@github.com>.
> +         assertEquals(g.getLaunchConfiguration().getPersonalities().get(0).getContents(), "VGhpcyBpcyBhIHRlc3QgZmlsZS4=");
> +         assertEquals(g.getLaunchConfiguration().getNetworks().size(), 2);
> +         assertEquals(g.getLaunchConfiguration().getNetworks().get(0), "11111111-1111-1111-1111-111111111111");
> +         assertEquals(g.getLaunchConfiguration().getNetworks().get(1), "00000000-0000-0000-0000-000000000000");
> +         assertEquals(g.getLaunchConfiguration().getServerMetadata().size(), 3);
> +         assertTrue(g.getLaunchConfiguration().getServerMetadata().containsKey("build_config"));
> +         assertTrue(g.getLaunchConfiguration().getServerMetadata().containsValue("core"));
> +         assertEquals(g.getLaunchConfiguration().getType(), LaunchConfigurationType.LAUNCH_SERVER);
> +
> +         assertEquals(g.getGroupConfiguration().getMaxEntities(), 10);
> +         assertEquals(g.getGroupConfiguration().getCooldown(), 360);
> +         assertEquals(g.getGroupConfiguration().getName(), "testscalinggroup198547");
> +         assertEquals(g.getGroupConfiguration().getMinEntities(), 0);
> +         assertEquals(g.getGroupConfiguration().getMetadata().size(), 2);
> +         assertTrue(g.getGroupConfiguration().getMetadata().containsKey("gc_meta_key_2"));
> +         assertTrue(g.getGroupConfiguration().getMetadata().containsValue("gc_meta_value_2"));

Some comment as above for `LaunchConfiguration` and `GroupConfiguration`. And for the `assertTrue`s, add a message to display what the *actual* value was, e.g.
```
 assertTrue(g.getGroupConfiguration().getMetadata().containsKey("gc_meta_key_2"), String.format("Expected metadata to contain 'gc_meta_key_2' but was: %s", g.getGroupConfiguration().getMetadata()));
```
?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59/files#r8266304

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-labs-openstack-pull-requests #110](https://jclouds.ci.cloudbees.com/job/jclouds-labs-openstack-pull-requests/110/) FAILURE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30260950

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Andrew Phillips <no...@github.com>.
> +import org.jclouds.rackspace.autoscale.v1.internal.BaseAutoscaleApiMockTest;
> +import org.testng.annotations.Test;
> +
> +import com.google.common.collect.FluentIterable;
> +import com.google.common.collect.ImmutableList;
> +import com.google.common.collect.ImmutableMap;
> +import com.google.common.collect.Lists;
> +import com.squareup.okhttp.mockwebserver.MockResponse;
> +import com.squareup.okhttp.mockwebserver.MockWebServer;
> +
> +/**
> + * Tests GroupApi Guice wiring and parsing
> + *
> + * @author Zack Shoylev
> + */
> +@Test//(groups = "unit", testName = "GroupApiMockTest")

Is the commented-out part intentional?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59/files#r8266232

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-labs-openstack-pull-requests #108](https://jclouds.ci.cloudbees.com/job/jclouds-labs-openstack-pull-requests/108/) FAILURE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30185253

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-labs-openstack #692](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-labs-openstack/692/) FAILURE
Looks like there's a problem with this pull request
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30185143

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Andrew Phillips <no...@github.com>.
> +          */
> +         assertNotNull(g);
> +         assertEquals(g.getId(),"6791761b-821a-4d07-820d-0b2afc7dd7f6");
> +         assertEquals(g.getLinks().size(), 1);
> +         assertEquals(g.getLinks().get(0).getHref().toString(), "https://ord.autoscale.api.rackspacecloud.com/v1.0/829409/groups/6791761b-821a-4d07-820d-0b2afc7dd7f6/");
> +         assertEquals(g.getLinks().get(0).getRelation(), Link.Relation.SELF);
> +
> +         assertEquals(g.getScalingPolicies().get(0).getId(), "dceb14ac-b2b3-4f06-aac9-a5b6cd5d40e1");
> +         assertEquals(g.getScalingPolicies().get(0).getLinks().size(), 1);
> +         assertEquals(g.getScalingPolicies().get(0).getLinks().get(0).getHref().toString(), "https://ord.autoscale.api.rackspacecloud.com/v1.0/829409/groups/6791761b-821a-4d07-820d-0b2afc7dd7f6/policies/dceb14ac-b2b3-4f06-aac9-a5b6cd5d40e1/");
> +         assertEquals(g.getScalingPolicies().get(0).getLinks().get(0).getRelation(), Link.Relation.SELF);
> +         assertEquals(g.getScalingPolicies().get(0).getCooldown(), 0);
> +         assertEquals(g.getScalingPolicies().get(0).getTarget(), "1");
> +         assertEquals(g.getScalingPolicies().get(0).getTargetType(), ScalingPolicyTargetType.INCREMENTAL);
> +         assertEquals(g.getScalingPolicies().get(0).getType(), ScalingPolicyType.WEBHOOK);
> +         assertEquals(g.getScalingPolicies().get(0).getName(), "scale up by 1");

Ouch ;-) Could you instead created an `expected` ScalingPolicy object and then simply do something like
```
assertEquals(g.getScalingPolicies().get(0), expected);
```
or does ScalingPolicy not do equals in the way that would be required for that?

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59/files#r8266271

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-labs-openstack #708](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-labs-openstack/708/) FAILURE
Looks like there's a problem with this pull request
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30260731

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Zack Shoylev <no...@github.com>.
Depends on https://github.com/jclouds/jclouds/pull/224

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30184651

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by CloudBees pull request builder plugin <no...@github.com>.
[jclouds-labs-openstack-pull-requests #109](https://jclouds.ci.cloudbees.com/job/jclouds-labs-openstack-pull-requests/109/) FAILURE
Looks like there's a problem with this pull request

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30251461

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by BuildHive <no...@github.com>.
[jclouds » jclouds-labs-openstack #705](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-labs-openstack/705/) FAILURE
Looks like there's a problem with this pull request
[(what's this?)](https://www.cloudbees.com/what-is-buildhive)

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30250768

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Zack Shoylev <no...@github.com>.
Build failure is expected.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30186049

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Zack Shoylev <no...@github.com>.
Ignore failures; will work when the jclouds snapshot gets updated.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30260914

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Zack Shoylev <no...@github.com>.
> +          */
> +         assertNotNull(g);
> +         assertEquals(g.getId(),"6791761b-821a-4d07-820d-0b2afc7dd7f6");
> +         assertEquals(g.getLinks().size(), 1);
> +         assertEquals(g.getLinks().get(0).getHref().toString(), "https://ord.autoscale.api.rackspacecloud.com/v1.0/829409/groups/6791761b-821a-4d07-820d-0b2afc7dd7f6/");
> +         assertEquals(g.getLinks().get(0).getRelation(), Link.Relation.SELF);
> +
> +         assertEquals(g.getScalingPolicies().get(0).getId(), "dceb14ac-b2b3-4f06-aac9-a5b6cd5d40e1");
> +         assertEquals(g.getScalingPolicies().get(0).getLinks().size(), 1);
> +         assertEquals(g.getScalingPolicies().get(0).getLinks().get(0).getHref().toString(), "https://ord.autoscale.api.rackspacecloud.com/v1.0/829409/groups/6791761b-821a-4d07-820d-0b2afc7dd7f6/policies/dceb14ac-b2b3-4f06-aac9-a5b6cd5d40e1/");
> +         assertEquals(g.getScalingPolicies().get(0).getLinks().get(0).getRelation(), Link.Relation.SELF);
> +         assertEquals(g.getScalingPolicies().get(0).getCooldown(), 0);
> +         assertEquals(g.getScalingPolicies().get(0).getTarget(), "1");
> +         assertEquals(g.getScalingPolicies().get(0).getTargetType(), ScalingPolicyTargetType.INCREMENTAL);
> +         assertEquals(g.getScalingPolicies().get(0).getType(), ScalingPolicyType.WEBHOOK);
> +         assertEquals(g.getScalingPolicies().get(0).getName(), "scale up by 1");

I remember there were issues with that. But I have find my notes on what issues exactly.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59/files#r8271317

Re: [jclouds-labs-openstack] Sample refactoring of GroupApiExpectTest to use MockWebServer (#59)

Posted by Zack Shoylev <no...@github.com>.
Note: refactoring the rest of the tests will be a separate PR

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds-labs-openstack/pull/59#issuecomment-30260782