Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gui tests #12

Merged
merged 12 commits into from
May 22, 2024
60 changes: 30 additions & 30 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Install TightVnc for UI tests
run: sudo apt-get install tightvncserver
- name: Add permission to run vnc script
run: chmod +x ./execute-on-vnc.sh
- name: Build with Maven
run: ./execute-on-vnc.sh mvn -B package --file pom.xml
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./execute-on-vnc.sh mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BME-MIT-IET_iet-hf-2024-iet-arcok
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Install TightVnc for UI tests
run: sudo apt-get install tightvncserver
- name: Add permission to run vnc script
run: chmod +x ./execute-on-vnc.sh
- name: Build with Maven
run: ./execute-on-vnc.sh mvn -B package --file pom.xml
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Maven packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./execute-on-vnc.sh mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=BME-MIT-IET_iet-hf-2024-iet-arcok
2 changes: 1 addition & 1 deletion execute-on-vnc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ export DISPLAY=:${NEW_DISPLAY}
"$@"

export DISPLAY=${OLD_DISPLAY}
vncserver -kill ":${NEW_DISPLAY}"
vncserver -kill ":${NEW_DISPLAY}"
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@
<version>0.8.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-swing-junit</artifactId>
<version>3.9.2</version>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
32 changes: 19 additions & 13 deletions src/main/java/ElementButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
public class ElementButton extends JButton{
private ArrayList<ImageIcon> statusimages = new ArrayList<ImageIcon>();
private transient Element element;
private JDialog dialog;
public static ArrayList<Pipe> holdingPipes = new ArrayList<Pipe>();

/**
Expand Down Expand Up @@ -54,7 +55,8 @@ public class ElementButton extends JButton{
{
@Override
public void actionPerformed(ActionEvent e) {
showActionButtonWindow();
JDialog dialog = showActionButtonWindow();
dialog.setVisible(true);
}
});
}
Expand Down Expand Up @@ -146,6 +148,7 @@ private int getElementIndexInNeighbors(Element e, boolean searchInParam)
}
private void initializeDialog(JDialog dialog) {
dialog.setTitle("Valassz a muveletek kozul");
dialog.setName(this.getName() + "Dialog");
dialog.setModal(true);
dialog.setLocation(400, 200);
dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
Expand Down Expand Up @@ -177,10 +180,10 @@ private boolean hasHoldingPump(Repairman repairman) {
private boolean hasNothingAndRepairMan(){
return isRepairman() && hasNothing(getCurrentRepairman()) ;
}
private void showActionButtonWindow() {
public JDialog showActionButtonWindow() {

//Ha a karakternek nincs már több lépése, akkor ne jelenjen meg a gomb, és jelzünk a Controlnak is.
if (isOutOfActions()) return;
if (isOutOfActions()) return null;

/** Letrehozunk egy JDialog objektumot es beallitjuk a tulajdonsagait.*/
/** */
Expand Down Expand Up @@ -211,16 +214,16 @@ private void showActionButtonWindow() {
getAndCreateMoveButton(place, closeButtonListener, buttonPanel, gbc);

//Ha az elemen végre lehet hajtani lyukasztást, akkor hozzáadunk egy ezt végrehajtó gombot
createButton(element.canPerformAction(Actions.STAB) && place == element, Actions.STAB, closeButtonListener, buttonPanel, gbc);
createButton(element.canPerformAction(Actions.STAB) && place == element, Actions.STAB, closeButtonListener, buttonPanel, gbc, Actions.STAB);

//Ha az elemen végre lehet hajtani pumpa lerakást, akkor hozzáadunk egy ezt végrehajtó gombot
createButton(isRepairman && element.canPerformAction(Actions.PLACE_PUMP) && place == element && ((Repairman) Game.getInstance().getCurrentCharacter()).hasHoldingPump(), Actions.PLACE_PUMP, closeButtonListener, buttonPanel, gbc);
createButton(isRepairman && element.canPerformAction(Actions.PLACE_PUMP) && place == element && ((Repairman) Game.getInstance().getCurrentCharacter()).hasHoldingPump(), Actions.PLACE_PUMP, closeButtonListener, buttonPanel, gbc, Actions.PLACE_PUMP);

//Ha az elemen végre lehet hajtani cső lerakást, akkor hozzáadunk egy ezt végrehajtó gombot
createButton(isRepairman && element.canPerformAction(Actions.PLACE_PIPE) && place == element && ((Repairman) Game.getInstance().getCurrentCharacter()).getHoldingPipe() != null, Actions.PLACE_PIPE, closeButtonListener, buttonPanel, gbc);
createButton(isRepairman && element.canPerformAction(Actions.PLACE_PIPE) && place == element && ((Repairman) Game.getInstance().getCurrentCharacter()).getHoldingPipe() != null, Actions.PLACE_PIPE, closeButtonListener, buttonPanel, gbc, Actions.PLACE_PIPE);

//Ha az elemen végre lehet hajtani pumpa felvételt, akkor hozzáadunk egy ezt végrehajtó gombot
createButton(isRepairman && element.canPerformAction(Actions.PICKUP_PUMP) && place == element && hasNothing, Actions.PICKUP_PUMP, closeButtonListener, buttonPanel, gbc);
createButton(isRepairman && element.canPerformAction(Actions.PICKUP_PUMP) && place == element && hasNothing, Actions.PICKUP_PUMP, closeButtonListener, buttonPanel, gbc, Actions.PICKUP_PUMP);

// Ha az elemen végre lehet hajtani cső felvételt, akkor hozzáadunk egy ezt végrehajtó gombot
if(isRepairman && element.canPerformAction(Actions.PICKUP_PIPE)&&place==element&&hasNothing) {
Expand All @@ -229,6 +232,7 @@ private void showActionButtonWindow() {
ArrayList<Integer> params = new ArrayList<Integer>();
params.add(getElementIndexInNeighbors(e, false));
ActionButton pickUpPipe = new ActionButton(params);
pickUpPipe.setName(this.getName() + Actions.PICKUP_PIPE);
pickUpPipe.setActionCommand(Actions.PICKUP_PIPE);
pickUpPipe.setText(Actions.PICKUP_PIPE + " " + e.getName());
pickUpPipe.addActionListener(closeButtonListener);
Expand All @@ -238,19 +242,20 @@ private void showActionButtonWindow() {
}

//Ha az elemen végre lehet hajtani javítást, akkor hozzáadunk egy ezt végrehajtó gombot
createButton(isRepairman && element.canPerformAction(Actions.REPAIR) && place == element && (element instanceof Pump && ((Pump) element).getBroken() || element instanceof Pipe && ((Pipe) element).getHoleOnPipe()), Actions.REPAIR, closeButtonListener, buttonPanel, gbc);
createButton(isRepairman && element.canPerformAction(Actions.REPAIR) && place == element && (element instanceof Pump && ((Pump) element).getBroken() || element instanceof Pipe && ((Pipe) element).getHoleOnPipe()), Actions.REPAIR, closeButtonListener, buttonPanel, gbc, Actions.REPAIR);

//Ha az elemen végre lehet hajtani ragadossá tételt, akkor hozzáadunk egy ezt végrehajtó gombot
createButton(element.canPerformAction(Actions.STICK) && place == element, Actions.STICK, closeButtonListener, buttonPanel, gbc);
createButton(element.canPerformAction(Actions.STICK) && place == element, Actions.STICK, closeButtonListener, buttonPanel, gbc, Actions.STICK);

//Ha az elemen végre lehet hajtani csúszóssá tételt, akkor hozzáadunk egy ezt végrehajtó gombot
createButton(!isRepairman && element.canPerformAction(Actions.SLIME) && place == element, Actions.SLIME, closeButtonListener, buttonPanel, gbc);
createButton(!isRepairman && element.canPerformAction(Actions.SLIME) && place == element, Actions.SLIME, closeButtonListener, buttonPanel, gbc, Actions.SLIME);

//Ha az elemen végre lehet hajtani be és kimenet állítást, akkor hozzáadunk ezeket végrehajtó gombokat
createInputAndOutputSetButtons(place, closeButtonListener, buttonPanel, gbc);

//Karakter körének véget vető gomb
ActionButton endMoveButton = new ActionButton(null);
endMoveButton.setName(this.getName() + Actions.END_MOVE);
endMoveButton.setActionCommand(Actions.END_MOVE);
endMoveButton.setText(Actions.END_MOVE);
endMoveButton.addActionListener(closeButtonListener);
Expand All @@ -263,8 +268,7 @@ private void showActionButtonWindow() {
/** A dialogus meretenek beallitasa a tartalomhoz*/
dialog.pack();

/** A dialogus megjelenitese */
dialog.setVisible(true);
return dialog;
}

private void createInputAndOutputSetButtons(Element place, ActionListener closeButtonListener, JPanel buttonPanel, GridBagConstraints gbc) {
Expand Down Expand Up @@ -295,9 +299,10 @@ private void createInputAndOutputSetButtons(Element place, ActionListener closeB
}
}

private void createButton(boolean element, String Stab, ActionListener closeButtonListener, JPanel buttonPanel, GridBagConstraints gbc) {
private void createButton(boolean element, String Stab, ActionListener closeButtonListener, JPanel buttonPanel, GridBagConstraints gbc, String nameSuffix) {
if (element) {
ActionButton stabButton = new ActionButton(null);
stabButton.setName(this.getName() + nameSuffix);
stabButton.setActionCommand(Stab);
stabButton.setText(Stab);
stabButton.addActionListener(closeButtonListener);
Expand Down Expand Up @@ -325,6 +330,7 @@ private void createMoveButton(Element place, ActionListener closeButtonListener,
ArrayList<Integer> params = new ArrayList<Integer>();
params.add(getElementIndexInNeighbors(place,true));
ActionButton moveButton = new ActionButton(params);
moveButton.setName(this.getName() + Actions.MOVE);
moveButton.setActionCommand(Actions.MOVE);
moveButton.setText(Actions.MOVE);
moveButton.addActionListener(closeButtonListener);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ public static Game getInstance()
{
return instance;
}

public static void resetInstance() {
instance = new Game();
}

/**
* Beállítja a Game megfelelő változóit.
Expand Down
Loading
Loading