Skip to content

Commit

Permalink
GEODE-7374: Fix class cast exception (apache#4247)
Browse files Browse the repository at this point in the history
Authored-by: Joris Melchior <[email protected]>
  • Loading branch information
jmelchio authored and jinmeiliao committed Oct 30, 2019
1 parent f6d7e85 commit d30e2e8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import org.apache.geode.management.cli.CommandServiceException;
import org.apache.geode.management.cli.CommandStatement;
import org.apache.geode.management.cli.Result;
import org.apache.geode.management.internal.cli.result.CommandResult;
import org.apache.geode.management.internal.cli.result.model.ResultModel;

/**
* @deprecated since 1.3 use OnlineCommandProcessor directly
Expand Down Expand Up @@ -49,7 +51,8 @@ public Result processCommand(String commandString) {

@Override
public Result processCommand(String commandString, Map<String, String> env) {
return (Result) onlineCommandProcessor.executeCommand(commandString, env, null);
ResultModel resultModel = onlineCommandProcessor.executeCommand(commandString, env, null);
return new CommandResult(resultModel);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.apache.geode.management.internal.cli.remote;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.Properties;

import org.junit.Before;
import org.junit.Test;

import org.apache.geode.distributed.DistributedSystem;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.security.SecurityService;
import org.apache.geode.management.cli.Result;

public class MemberCommandServiceTest {
private InternalCache cache;

@Before
public void init() {
cache = mock(InternalCache.class);
DistributedSystem distributedSystem = mock(DistributedSystem.class);
SecurityService securityService = mock(SecurityService.class);
Properties cacheProperties = new Properties();

when(cache.getDistributedSystem()).thenReturn(distributedSystem);
when(cache.isClosed()).thenReturn(true);
when(cache.getSecurityService()).thenReturn(securityService);
when(distributedSystem.getProperties()).thenReturn(cacheProperties);
}

@Test
public void processCommandError() throws Exception {
MemberCommandService memberCommandService = new MemberCommandService(cache);

Result result = memberCommandService.processCommand("fake command");

assertThat(result.getStatus()).isEqualTo(Result.Status.ERROR);
}
}

0 comments on commit d30e2e8

Please sign in to comment.