Eclipseplugins
RunProgramInPaTest.java
1 package com.proalpha.pds.tests.paconnector;
2 
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.fail;
5 
6 import java.io.File;
7 
8 import org.eclipse.core.runtime.CoreException;
9 import org.eclipse.core.runtime.IProgressMonitor;
10 import org.eclipse.core.runtime.Path;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.mockito.Mock;
14 import org.mockito.Mockito;
15 import org.mockito.MockitoAnnotations;
16 
17 import com.openedge.core.runtime.IAVMClient;
18 import com.openedge.core.runtime.IAVMConnection;
19 import com.openedge.core.runtime.IAVMRuntimeConfiguration;
20 import com.openedge.core.runtime.IAVMRuntimeListener;
21 import com.openedge.core.runtime.IPropath;
22 import com.openedge.core.runtime.ProgressCommand;
23 import com.openedge.core.util.Semaphore;
24 import com.openedge.pdt.platform.Proversion;
25 import com.openedge.pdt.project.OEProject;
26 import com.proalpha.pds.exception.ProALPHANotAvailableException;
27 import com.proalpha.pds.paconnector.PaProject;
28 import com.proalpha.pds.paconnector.RunProgramInPa;
29 
30 public class RunProgramInPaTest {
31 
32  private String testDir;
33  private IAVMClient avmclient;
34 
35  @Mock
36  private OEProject oeProject;
37  @Mock
38  private IPropath proPath;
39  @Mock
40  private ProgressCommand cmd;
41  @Mock
42  private PaProject paProject;
43 
44  @Before
45  public void init() {
46  MockitoAnnotations.initMocks(this);
47  avmclient = new MockedAVMClient();
48  testDir = new File("src/test").getAbsolutePath();
49  Mockito.when(proPath.search("paoidebr.p", true)).thenReturn(new Path(testDir));
50  Mockito.when(proPath.search("adm/support/proc/ds_oea36.p", true))
51  .thenReturn(new Path(new File("src/test/ds_oea36.p").getAbsolutePath()));
52  Mockito.when(proPath.search("adm/support/proc/ds_oea06.p", true))
53  .thenReturn(new Path(new File("src/test/ds_oea06.p").getAbsolutePath()));
54  Mockito.when(cmd.isFinished()).thenReturn(true);
55  Mockito.when(oeProject.getPropath()).thenReturn(proPath);
56  Mockito.when(oeProject.getRuntime()).thenReturn(avmclient);
57  Mockito.when(paProject.getOeProject()).thenReturn(oeProject);
58  Mockito.when(paProject.getBridgePath()).thenReturn(new Path(testDir));
59  }
60 
61  @Test
62  public void testInitialize() {
63 
64  try {
65  RunProgramInPa paProgram = new RunProgramInPa(paProject);
66  assertEquals("Should be equal", "UTF-8", paProgram.getpAStartupParam("justatest", "EMPTY"));
67  } catch (ProALPHANotAvailableException e) {
68  fail(e.getMessage());
69  }
70 
71  }
72 
73  @Test(expected = ProALPHANotAvailableException.class)
74  public void testThrowPaNotAvailException() throws ProALPHANotAvailableException {
75  Mockito.when(proPath.search("paoidebr.p", true)).thenReturn(null);
76  RunProgramInPa paProgram = new RunProgramInPa(paProject);
77  }
78 
79 }
80 
81 class MockedAVMClient implements IAVMClient {
82 
87  @Override
88  public void runProgressCommand(ProgressCommand cmd) {
89  cmd.setResult("UTF-8");
90  cmd.setCompletionStatus(1);
91  }
92 
93  @Override
94  public void addAVMRuntimeListener(IAVMRuntimeListener arg0) {
95  }
96 
97  @Override
98  public void bringToTop() {
99  }
100 
101  @Override
102  public void connect(IAVMConnection arg0) {
103  }
104 
105  @Override
106  public IAVMRuntimeConfiguration getConfiguration() {
107  return null;
108  }
109 
110  @Override
111  public String getName() {
112  return null;
113  }
114 
115  @Override
116  public Proversion getProversion() {
117  return null;
118  }
119 
120  @Override
121  public Semaphore getRuntimeSemaphore() {
122  return null;
123  }
124 
125  @Override
126  public int getWindowThreadId() {
127  return 0;
128  }
129 
130  @Override
131  public boolean isAvailable() {
132  return false;
133  }
134 
135  @Override
136  public boolean isConnected() {
137  return false;
138  }
139 
140  @Override
141  public boolean isShared() {
142  return false;
143  }
144 
145  @Override
146  public boolean isTTY() {
147  return false;
148  }
149 
150  @Override
151  public void removeAVMRuntimeListener(IAVMRuntimeListener arg0) {
152  }
153 
154  @Override
155  public void restart(IProgressMonitor arg0) throws CoreException {
156  }
157 
158  @Override
159  public void setRuntimeProcess(Process arg0) {
160  }
161 
162  @Override
163  public void start(IProgressMonitor arg0) throws CoreException {
164  }
165 
166  @Override
167  public void stop(IProgressMonitor arg0) {
168  }
169 
170 }