Skip to content

Commit

Permalink
Rename MachineTypeId.machineType() to type()
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Apr 26, 2016
1 parent 4ea0529 commit 51582ba
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,7 @@ public MachineType getMachineType(final MachineTypeId machineType, MachineTypeOp
runWithRetries(new Callable<com.google.api.services.compute.model.MachineType>() {
@Override
public com.google.api.services.compute.model.MachineType call() {
return computeRpc.getMachineType(machineType.zone(), machineType.machineType(),
optionsMap);
return computeRpc.getMachineType(machineType.zone(), machineType.type(), optionsMap);
}
}, options().retryParams(), EXCEPTION_HANDLER);
return answer == null ? null : MachineType.fromPb(answer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ com.google.api.services.compute.model.MachineType toPb() {
if (creationTimestamp != null) {
machineTypePb.setCreationTimestamp(TIMESTAMP_FORMATTER.print(creationTimestamp));
}
machineTypePb.setName(machineTypeId.machineType());
machineTypePb.setName(machineTypeId.type());
machineTypePb.setDescription(description);
machineTypePb.setSelfLink(machineTypeId.selfLink());
machineTypePb.setGuestCpus(cpus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,19 @@ public String apply(MachineTypeId machineTypeId) {
private static final long serialVersionUID = -5819598544478859608L;

private final String zone;
private final String machineType;
private final String type;

private MachineTypeId(String project, String zone, String machineType) {
private MachineTypeId(String project, String zone, String type) {
super(project);
this.zone = checkNotNull(zone);
this.machineType = checkNotNull(machineType);
this.type = checkNotNull(type);
}

/**
* Returns the name of the machine type.
*/
public String machineType() {
return machineType;
public String type() {
return type;
}

/**
Expand All @@ -81,17 +81,17 @@ public ZoneId zoneId() {

@Override
public String selfLink() {
return super.selfLink() + "/zones/" + zone + "/machineTypes/" + machineType;
return super.selfLink() + "/zones/" + zone + "/machineTypes/" + type;
}

@Override
MoreObjects.ToStringHelper toStringHelper() {
return super.toStringHelper().add("zone", zone).add("machineType", machineType);
return super.toStringHelper().add("zone", zone).add("type", type);
}

@Override
public int hashCode() {
return Objects.hash(baseHashCode(), zone, machineType);
return Objects.hash(baseHashCode(), zone, type);
}

@Override
Expand All @@ -105,29 +105,29 @@ public boolean equals(Object obj) {
MachineTypeId other = (MachineTypeId) obj;
return baseEquals(other)
&& Objects.equals(zone, other.zone)
&& Objects.equals(machineType, other.machineType);
&& Objects.equals(type, other.type);
}

@Override
MachineTypeId setProjectId(String projectId) {
if (project() != null) {
return this;
}
return MachineTypeId.of(projectId, zone, machineType);
return MachineTypeId.of(projectId, zone, type);
}

/**
* Returns a machine type identity given the zone and type names.
*/
public static MachineTypeId of(String zone, String machineType) {
return new MachineTypeId(null, zone, machineType);
public static MachineTypeId of(String zone, String type) {
return new MachineTypeId(null, zone, type);
}

/**
* Returns a machine type identity given project, zone and type names.
*/
public static MachineTypeId of(String project, String zone, String machineType) {
return new MachineTypeId(project, zone, machineType);
public static MachineTypeId of(String project, String zone, String type) {
return new MachineTypeId(project, zone, type);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,30 +748,30 @@ public void testAggregatedListDiskTypesWithOptions() {
public void testGetMachineType() {
EasyMock.expect(
computeRpcMock.getMachineType(
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType(), EMPTY_RPC_OPTIONS))
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andReturn(MACHINE_TYPE.toPb());
EasyMock.replay(computeRpcMock);
compute = options.service();
MachineType machineType =
compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType());
compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type());
assertEquals(MACHINE_TYPE, machineType);
}

@Test
public void testGetMachineType_Null() {
EasyMock.expect(
computeRpcMock.getMachineType(
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType(), EMPTY_RPC_OPTIONS))
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andReturn(null);
EasyMock.replay(computeRpcMock);
compute = options.service();
assertNull(compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType()));
assertNull(compute.getMachineType(MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type()));
}

@Test
public void testGetMachineTypeFromMachineTypeId() {
EasyMock.expect(computeRpcMock.getMachineType(
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.machineType(), EMPTY_RPC_OPTIONS))
MACHINE_TYPE_ID.zone(), MACHINE_TYPE_ID.type(), EMPTY_RPC_OPTIONS))
.andReturn(MACHINE_TYPE.toPb());
EasyMock.replay(computeRpcMock);
compute = options.service();
Expand All @@ -783,13 +783,13 @@ public void testGetMachineTypeFromMachineTypeId() {
public void testGetMachineTypeWithSelectedFields() {
Capture<Map<ComputeRpc.Option, Object>> capturedOptions = Capture.newInstance();
EasyMock.expect(
computeRpcMock.getMachineType(eq(MACHINE_TYPE_ID.zone()), eq(MACHINE_TYPE_ID.machineType()),
computeRpcMock.getMachineType(eq(MACHINE_TYPE_ID.zone()), eq(MACHINE_TYPE_ID.type()),
capture(capturedOptions)))
.andReturn(MACHINE_TYPE.toPb());
EasyMock.replay(computeRpcMock);
compute = options.service();
MachineType machineType = compute.getMachineType(MACHINE_TYPE_ID.zone(),
MACHINE_TYPE_ID.machineType(), MACHINE_TYPE_OPTION_FIELDS);
MACHINE_TYPE_ID.type(), MACHINE_TYPE_OPTION_FIELDS);
String selector = (String) capturedOptions.getValue().get(DISK_TYPE_OPTION_FIELDS.rpcOption());
assertTrue(selector.contains("selfLink"));
assertTrue(selector.contains("id"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ public void testOf() {
MachineTypeId machineTypeId = MachineTypeId.of(PROJECT, ZONE, TYPE);
assertEquals(PROJECT, machineTypeId.project());
assertEquals(ZONE, machineTypeId.zone());
assertEquals(TYPE, machineTypeId.machineType());
assertEquals(TYPE, machineTypeId.type());
assertEquals(URL, machineTypeId.selfLink());
machineTypeId = MachineTypeId.of(ZONE, TYPE);
assertNull(machineTypeId.project());
assertEquals(ZONE, machineTypeId.zone());
assertEquals(TYPE, machineTypeId.machineType());
assertEquals(TYPE, machineTypeId.type());
}

@Test
Expand Down Expand Up @@ -76,7 +76,7 @@ private void compareMachineTypeId(MachineTypeId expected, MachineTypeId value) {
assertEquals(expected, value);
assertEquals(expected.project(), expected.project());
assertEquals(expected.zone(), expected.zone());
assertEquals(expected.machineType(), expected.machineType());
assertEquals(expected.type(), expected.type());
assertEquals(expected.selfLink(), expected.selfLink());
assertEquals(expected.hashCode(), expected.hashCode());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public void testAggregatedListDiskTypesWithFilter() {
public void testGetMachineType() {
MachineType machineType = compute.getMachineType(ZONE, MACHINE_TYPE);
assertEquals(ZONE, machineType.machineTypeId().zone());
assertEquals(MACHINE_TYPE, machineType.machineTypeId().machineType());
assertEquals(MACHINE_TYPE, machineType.machineTypeId().type());
assertNotNull(machineType.id());
assertNotNull(machineType.creationTimestamp());
assertNotNull(machineType.description());
Expand All @@ -231,7 +231,7 @@ public void testGetMachineTypeWithSelectedFields() {
MachineType machineType = compute.getMachineType(ZONE, MACHINE_TYPE,
Compute.MachineTypeOption.fields(Compute.MachineTypeField.ID));
assertEquals(ZONE, machineType.machineTypeId().zone());
assertEquals(MACHINE_TYPE, machineType.machineTypeId().machineType());
assertEquals(MACHINE_TYPE, machineType.machineTypeId().type());
assertNotNull(machineType.id());
assertNull(machineType.creationTimestamp());
assertNull(machineType.description());
Expand Down

0 comments on commit 51582ba

Please sign in to comment.