23
23
import com .datastax .mgmtapi .resources .NodeOpsResources ;
24
24
import com .datastax .mgmtapi .resources .TableOpsResources ;
25
25
import com .datastax .mgmtapi .resources .models .CompactRequest ;
26
- import com .datastax .mgmtapi .resources .models .CreateKeyspaceRequest ;
26
+ import com .datastax .mgmtapi .resources .models .CreateOrAlterKeyspaceRequest ;
27
27
import com .datastax .mgmtapi .resources .models .KeyspaceRequest ;
28
28
import com .datastax .mgmtapi .resources .models .ReplicationSetting ;
29
29
import com .datastax .mgmtapi .resources .models .ScrubRequest ;
30
- import org .apache .http .ConnectionClosedException ;
31
30
import org .apache .http .HttpStatus ;
32
- import org .assertj .core .api .Assertions ;
33
31
import org .jboss .resteasy .core .messagebody .WriterUtility ;
34
32
import org .jboss .resteasy .mock .MockDispatcherFactory ;
35
33
import org .jboss .resteasy .mock .MockHttpRequest ;
@@ -1000,7 +998,7 @@ public void testGetStreamInfo() throws Exception
1000
998
@ Test
1001
999
public void testCreatingKeyspace () throws IOException , URISyntaxException
1002
1000
{
1003
- CreateKeyspaceRequest keyspaceRequest = new CreateKeyspaceRequest ("myKeyspace" , Arrays .asList (new ReplicationSetting ("dc1" , 3 ), new ReplicationSetting ("dc2" , 3 )));
1001
+ CreateOrAlterKeyspaceRequest keyspaceRequest = new CreateOrAlterKeyspaceRequest ("myKeyspace" , Arrays .asList (new ReplicationSetting ("dc1" , 3 ), new ReplicationSetting ("dc2" , 3 )));
1004
1002
1005
1003
Context context = setup ();
1006
1004
@@ -1019,7 +1017,7 @@ public void testCreatingKeyspace() throws IOException, URISyntaxException
1019
1017
@ Test
1020
1018
public void testCreatingEmptyKeyspaceShouldFail () throws IOException , URISyntaxException
1021
1019
{
1022
- CreateKeyspaceRequest keyspaceRequest = new CreateKeyspaceRequest ("" , Arrays .asList (new ReplicationSetting ("dc1" , 3 ), new ReplicationSetting ("dc2" , 3 )));
1020
+ CreateOrAlterKeyspaceRequest keyspaceRequest = new CreateOrAlterKeyspaceRequest ("" , Arrays .asList (new ReplicationSetting ("dc1" , 3 ), new ReplicationSetting ("dc2" , 3 )));
1023
1021
1024
1022
Context context = setup ();
1025
1023
@@ -1036,7 +1034,7 @@ public void testCreatingEmptyKeyspaceShouldFail() throws IOException, URISyntaxE
1036
1034
@ Test
1037
1035
public void testCreatingEmptyReplicationSettingsShouldFail () throws IOException , URISyntaxException
1038
1036
{
1039
- CreateKeyspaceRequest keyspaceRequest = new CreateKeyspaceRequest ("TestKeyspace" , Collections .emptyList ());
1037
+ CreateOrAlterKeyspaceRequest keyspaceRequest = new CreateOrAlterKeyspaceRequest ("TestKeyspace" , Collections .emptyList ());
1040
1038
1041
1039
Context context = setup ();
1042
1040
@@ -1050,6 +1048,59 @@ public void testCreatingEmptyReplicationSettingsShouldFail() throws IOException,
1050
1048
assertThat (response .getContentAsString ()).contains ("Keyspace creation failed. 'replication_settings' must be provided" );
1051
1049
}
1052
1050
1051
+ @ Test
1052
+ public void testAlteringKeyspace () throws IOException , URISyntaxException
1053
+ {
1054
+ CreateOrAlterKeyspaceRequest keyspaceRequest = new CreateOrAlterKeyspaceRequest ("myKeyspace" , Arrays .asList (new ReplicationSetting ("dc1" , 3 ), new ReplicationSetting ("dc2" , 3 )));
1055
+
1056
+ Context context = setup ();
1057
+
1058
+ when (context .cqlService .executePreparedStatement (any (), anyString ()))
1059
+ .thenReturn (null );
1060
+
1061
+ String keyspaceRequestAsJSON = WriterUtility .asString (keyspaceRequest , MediaType .APPLICATION_JSON );
1062
+ MockHttpResponse response = postWithBody ("/ops/keyspace/alter" , keyspaceRequestAsJSON , context );
1063
+
1064
+ assertThat (response .getStatus ()).isEqualTo (HttpStatus .SC_OK );
1065
+ assertThat (response .getContentAsString ()).contains ("OK" );
1066
+
1067
+ verify (context .cqlService ).executePreparedStatement (any (), eq ("CALL NodeOps.alterKeyspace(?, ?)" ), any ());
1068
+ }
1069
+
1070
+ @ Test
1071
+ public void testAlteringEmptyKeyspaceShouldFail () throws IOException , URISyntaxException
1072
+ {
1073
+ CreateOrAlterKeyspaceRequest keyspaceRequest = new CreateOrAlterKeyspaceRequest ("" , Arrays .asList (new ReplicationSetting ("dc1" , 3 ), new ReplicationSetting ("dc2" , 3 )));
1074
+
1075
+ Context context = setup ();
1076
+
1077
+ when (context .cqlService .executePreparedStatement (any (), anyString ()))
1078
+ .thenReturn (null );
1079
+
1080
+ String keyspaceRequestAsJSON = WriterUtility .asString (keyspaceRequest , MediaType .APPLICATION_JSON );
1081
+ MockHttpResponse response = postWithBody ("/ops/keyspace/alter" , keyspaceRequestAsJSON , context );
1082
+
1083
+ assertThat (response .getStatus ()).isEqualTo (HttpStatus .SC_BAD_REQUEST );
1084
+ assertThat (response .getContentAsString ()).contains ("Altering Keyspace failed. Non-empty 'keyspace_name' must be provided" );
1085
+ }
1086
+
1087
+ @ Test
1088
+ public void testAlteringEmptyReplicationSettingsShouldFail () throws IOException , URISyntaxException
1089
+ {
1090
+ CreateOrAlterKeyspaceRequest keyspaceRequest = new CreateOrAlterKeyspaceRequest ("TestKeyspace" , Collections .emptyList ());
1091
+
1092
+ Context context = setup ();
1093
+
1094
+ when (context .cqlService .executePreparedStatement (any (), anyString ()))
1095
+ .thenReturn (null );
1096
+
1097
+ String keyspaceRequestAsJSON = WriterUtility .asString (keyspaceRequest , MediaType .APPLICATION_JSON );
1098
+ MockHttpResponse response = postWithBody ("/ops/keyspace/alter" , keyspaceRequestAsJSON , context );
1099
+
1100
+ assertThat (response .getStatus ()).isEqualTo (HttpStatus .SC_BAD_REQUEST );
1101
+ assertThat (response .getContentAsString ()).contains ("Altering Keyspace failed. 'replication_settings' must be provided" );
1102
+ }
1103
+
1053
1104
private MockHttpResponse postWithBody (String path , String body , Context context ) throws URISyntaxException {
1054
1105
MockHttpRequest request = MockHttpRequest
1055
1106
.post (ROOT_PATH + path )
0 commit comments